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

Function replace_directory

atomic-repository/src/repository/operation.rs:5118–5144  ·  view source on GitHub ↗
(path: &Path, source: &Path, mode: u32)

Source from the content-addressed store, hash-verified

5116}
5117
5118fn replace_directory(path: &Path, source: &Path, mode: u32) -> Result<(), RepositoryError> {
5119 let parent = path
5120 .parent()
5121 .ok_or_else(|| RepositoryError::InvalidOperation {
5122 message: format!(
5123 "cannot replace directory without parent: {}",
5124 path.display()
5125 ),
5126 })?;
5127 fs::create_dir_all(parent)?;
5128 if fs::symlink_metadata(path).is_ok() {
5129 return Err(RepositoryError::InvalidOperation {
5130 message: format!(
5131 "directory recovery target must be absent before replacement: {}",
5132 path.display()
5133 ),
5134 });
5135 }
5136 let staging = tempfile::Builder::new()
5137 .prefix(".atomic-recover-dir-")
5138 .tempdir_in(parent)?;
5139 let prepared = staging.path().join(BACKUP_VALUE);
5140 copy_entry(source, &prepared)?;
5141 set_mode(&prepared, mode)?;
5142 fs::rename(&prepared, path)?;
5143 sync_directory(parent)
5144}
5145
5146fn replace_symlink(path: &Path, source: &Path) -> Result<(), RepositoryError> {
5147 let parent = path

Callers 1

Calls 6

copy_entryFunction · 0.85
sync_directoryFunction · 0.85
parentMethod · 0.80
set_modeFunction · 0.70
prefixMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected