mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
feat: make cas files readonly
This commit is contained in:
parent
00db2a51c2
commit
2a136f11db
1 changed files with 13 additions and 2 deletions
|
@ -38,7 +38,13 @@ pub(crate) fn store_in_cas<P: AsRef<Path>>(
|
|||
|
||||
let cas_path = folder.join(rest);
|
||||
if !cas_path.exists() {
|
||||
std::fs::write(&cas_path, contents)?;
|
||||
let mut file = std::fs::File::create(&cas_path)?;
|
||||
file.write_all(contents)?;
|
||||
|
||||
// prevent the CAS from being corrupted due to accidental modifications
|
||||
let mut permissions = file.metadata()?.permissions();
|
||||
permissions.set_readonly(true);
|
||||
file.set_permissions(permissions)?;
|
||||
}
|
||||
|
||||
Ok((hash, cas_path))
|
||||
|
@ -73,7 +79,12 @@ pub(crate) fn store_reader_in_cas<P: AsRef<Path>>(
|
|||
|
||||
let cas_path = folder.join(rest);
|
||||
match file_writer.into_inner()?.persist_noclobber(cas_path) {
|
||||
Ok(_) => {}
|
||||
Ok(f) => {
|
||||
// prevent the CAS from being corrupted due to accidental modifications
|
||||
let mut permissions = f.metadata()?.permissions();
|
||||
permissions.set_readonly(true);
|
||||
f.set_permissions(permissions)?;
|
||||
}
|
||||
Err(e) if e.error.kind() == std::io::ErrorKind::AlreadyExists => {}
|
||||
Err(e) => return Err(e.error),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue