(path: &Path, source: &Path, mode: u32)
| 5116 | } |
| 5117 | |
| 5118 | fn 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 | |
| 5146 | fn replace_symlink(path: &Path, source: &Path) -> Result<(), RepositoryError> { |
| 5147 | let parent = path |
no test coverage detected