pub(crate) mod gen_c;
pub(crate) mod vendor_c;
use std::fs;
use std::path::Path;
use crate::CliResult;
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum WriteOutcome {
Created,
Updated,
Unchanged,
}
#[aristo::intent(
"Re-emitting identical content leaves the file byte-identical and returns \
Unchanged; Created (file absent) and Updated (content differed) are the \
other two outcomes. Idempotence is the Unchanged case specifically — a \
re-run on up-to-date output must not rewrite the file, which would churn \
its mtime and dirty a clean tree. Shared by vendor-c and gen-c.",
verify = "test",
id = "instrument_write_is_idempotent"
)]
pub(crate) fn write_file(path: &Path, content: &str) -> CliResult<WriteOutcome> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
if path.exists() {
let existing = fs::read_to_string(path)?;
if existing == content {
return Ok(WriteOutcome::Unchanged);
}
fs::write(path, content)?;
return Ok(WriteOutcome::Updated);
}
fs::write(path, content)?;
Ok(WriteOutcome::Created)
}
pub(crate) const ARISTO_ABI: u32 = 1;