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

Function write_atomic_regular

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

Source from the content-addressed store, hash-verified

5023}
5024
5025fn 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
5055fn write_atomic_symlink(path: &Path, target: &[u8]) -> Result<(), RepositoryError> {
5056 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