use std::path::Path;
use csp_format::{Error, Result};
pub fn check(out: &Path, inputs: &[&Path]) -> Result<()> {
if !out.exists() {
return Ok(());
}
for input in inputs {
if same_file::is_same_file(out, input).unwrap_or(false) {
return Err(Error::format(format!(
"{} is the input {}; write the output to another file (inputs are never replaced)",
out.display(),
input.display()
)));
}
}
Ok(())
}
pub fn write(out: &Path, bytes: impl AsRef<[u8]>, inputs: &[&Path]) -> Result<()> {
check(out, inputs)?;
std::fs::write(out, bytes)?;
Ok(())
}