feat: enhance safety filters for shell commands by normalizing ANSI-C quoting
This commit is contained in:
+16
-2
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user