MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / write_file_atomically

Method write_file_atomically

src/storage.rs:494–514  ·  view source on GitHub ↗
(path: &Path, temp_path: &Path, contents: &[u8])

Source from the content-addressed store, hash-verified

492 }
493
494 pub fn write_file_atomically(path: &Path, temp_path: &Path, contents: &[u8]) -> io::Result<()> {
495 if path_parent(path) != path_parent(temp_path) {
496 return Err(invalid_input(
497 "private store atomic write temp path must share the target directory",
498 ));
499 }
500 if path == temp_path {
501 return Err(invalid_input(
502 "private store atomic write temp path must differ from the target",
503 ));
504 }
505 if let Some(parent) = path.parent() {
506 Self::create_dir_all(parent)?;
507 }
508 reject_symlink_components(path, "private store file")?;
509 reject_symlink_components(temp_path, "private store temp file")?;
510 fs::write(temp_path, contents)?;
511 set_private_file_permissions(temp_path)?;
512 fs::rename(temp_path, path)?;
513 set_private_file_permissions(path)
514 }
515
516 pub fn copy_artifact(source: &Path, target: &Path) -> io::Result<u64> {
517 let meta = source.symlink_metadata()?;

Callers

nothing calls this directly

Calls 5

path_parentFunction · 0.85
invalid_inputFunction · 0.85
writeFunction · 0.85

Tested by

no test coverage detected