MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / rename_and_sync

Function rename_and_sync

atomic-repository/src/repository/switch.rs:67–91  ·  view source on GitHub ↗

Remove empty ancestor directories after file removal. Given an iterator of relative paths that were just deleted, this collects every parent directory, sorts them deepest-first, and attempts `std::fs::remove_dir` on each. Because `remove_dir` only succeeds on *empty* directories, this is always safe — a directory that still contains files (tracked, untracked, or otherwise) will simply fail silen

(source: &Path, destination: &Path)

Source from the content-addressed store, hash-verified

65/// orchestration level and makes the cleanup logic reusable for other
66/// operations (e.g. `atomic clean`).
67fn rename_and_sync(source: &Path, destination: &Path) -> Result<(), RepositoryError> {
68 std::fs::rename(source, destination)?;
69 #[cfg(unix)]
70 {
71 let source_parent = source
72 .parent()
73 .ok_or_else(|| RepositoryError::InvalidOperation {
74 message: format!("rename source has no parent: {}", source.display()),
75 })?;
76 std::fs::File::open(source_parent)?.sync_all()?;
77 if source_parent != destination {
78 let destination_parent =
79 destination
80 .parent()
81 .ok_or_else(|| RepositoryError::InvalidOperation {
82 message: format!(
83 "rename destination has no parent: {}",
84 destination.display()
85 ),
86 })?;
87 std::fs::File::open(destination_parent)?.sync_all()?;
88 }
89 }
90 Ok(())
91}
92
93fn operation_timestamp_ms() -> i64 {
94 std::time::SystemTime::now()

Callers 2

execute_shelve_pathMethod · 0.85
execute_restore_pathMethod · 0.85

Calls 2

openFunction · 0.85
parentMethod · 0.80

Tested by

no test coverage detected