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