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

Function verify_existing

atomic-repository/src/repository/changes.rs:1877–1895  ·  view source on GitHub ↗
(path: &Path, expected: &[u8])

Source from the content-addressed store, hash-verified

1875) -> Result<(), RepositoryError> {
1876 use std::io::Write;
1877 fn verify_existing(path: &Path, expected: &[u8]) -> Result<(), RepositoryError> {
1878 let metadata = std::fs::symlink_metadata(path)?;
1879 if !metadata.file_type().is_file() || std::fs::read(path)? != expected {
1880 return Err(RepositoryError::InvalidOperation {
1881 message: format!("projected change object '{}' already exists with different bytes; refusing to overwrite it", path.display()),
1882 });
1883 }
1884 // A prior process may have linked the complete object but died before
1885 // syncing the containing directory. Finish that durability step when
1886 // reusing an identical object.
1887 std::fs::File::open(path)?.sync_all()?;
1888 let parent = path
1889 .parent()
1890 .ok_or_else(|| RepositoryError::InvalidOperation {
1891 message: "projected change path has no parent".into(),
1892 })?;
1893 std::fs::File::open(parent)?.sync_all()?;
1894 Ok(())
1895 }
1896 match std::fs::symlink_metadata(path) {
1897 Ok(_) => return verify_existing(path, bytes),
1898 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}

Calls 4

openFunction · 0.85
parentMethod · 0.80
readFunction · 0.50
is_fileMethod · 0.45

Tested by

no test coverage detected