feat: enhance safety filters for shell commands by normalizing ANSI-C quoting

This commit is contained in:
asepharyana
2026-07-13 04:10:08 +07:00
parent a080957c26
commit d09e440e7e
14 changed files with 383 additions and 85 deletions
+16 -2
View File
@@ -92,8 +92,22 @@ impl Memory {
self.content
);
let tmp = parent.join(format!(".{}.tmp", uuid::Uuid::new_v4()));
std::fs::write(&tmp, &content)?;
std::fs::rename(&tmp, path)?;
// Write to temp file with fsync for crash safety (prevents
// partial writes surviving a power loss).
{
let mut f = std::fs::OpenOptions::new()
.create(true)
.write(true)
.open(&tmp)?;
use std::io::Write;
f.write_all(content.as_bytes())?;
f.sync_all()?;
}
std::fs::rename(&tmp, &path)?;
// Sync the parent directory so the rename is durable.
if let Some(p) = path.parent() {
let _ = std::fs::File::open(p).and_then(|d| d.sync_all());
}
Ok(())
}