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)
| 65 | /// orchestration level and makes the cleanup logic reusable for other |
| 66 | /// operations (e.g. `atomic clean`). |
| 67 | fn 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 | |
| 93 | fn operation_timestamp_ms() -> i64 { |
| 94 | std::time::SystemTime::now() |
no test coverage detected