(path: &Path, bytes: &[u8], mode: u32)
| 5023 | } |
| 5024 | |
| 5025 | fn write_atomic_regular(path: &Path, bytes: &[u8], mode: u32) -> Result<(), RepositoryError> { |
| 5026 | let parent = path |
| 5027 | .parent() |
| 5028 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 5029 | message: format!( |
| 5030 | "cannot atomically replace path without parent: {}", |
| 5031 | path.display() |
| 5032 | ), |
| 5033 | })?; |
| 5034 | fs::create_dir_all(parent)?; |
| 5035 | let mut temporary = tempfile::NamedTempFile::new_in(parent)?; |
| 5036 | temporary.as_file_mut().write_all(bytes)?; |
| 5037 | set_mode(temporary.path(), mode)?; |
| 5038 | temporary.as_file_mut().sync_all()?; |
| 5039 | if matches!(fs::symlink_metadata(path), Ok(metadata) if metadata.is_dir()) |
| 5040 | && !remove_materialized_gitlink(path)? |
| 5041 | { |
| 5042 | return Err(RepositoryError::InvalidOperation { |
| 5043 | message: format!( |
| 5044 | "refusing to replace directory '{}' with a regular file", |
| 5045 | path.display() |
| 5046 | ), |
| 5047 | }); |
| 5048 | } |
| 5049 | temporary |
| 5050 | .persist(path) |
| 5051 | .map_err(|error| RepositoryError::Io(error.error))?; |
| 5052 | sync_directory(parent) |
| 5053 | } |
| 5054 | |
| 5055 | fn write_atomic_symlink(path: &Path, target: &[u8]) -> Result<(), RepositoryError> { |
| 5056 | let parent = path |
no test coverage detected