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

Function write_atomic_regular

atomic-repository/src/repository/operation.rs:5021–5049  ·  view source on GitHub ↗
(path: &Path, bytes: &[u8], mode: u32)

Source from the content-addressed store, hash-verified

5019}
5020
5021fn 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
5051fn write_atomic_symlink(path: &Path, target: &[u8]) -> Result<(), RepositoryError> {
5052 let parent = path

Calls 5

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

Tested by

no test coverage detected