remotefilelog: set proper file permissions on closed mutable packs.

Summary:
The python version of the mutable packs set the permission to read-only after
writing them, while the rust version keeps them writeable. Let's make the rust
one more consistent.

Reviewed By: markbt

Differential Revision: D13573572

fbshipit-source-id: 61256994562aa09058a88a7935c16dfd7ddf9d18
This commit is contained in:
Xavier Deguillard 2019-01-11 16:49:34 -08:00 committed by Facebook Github Bot
parent 603daf671b
commit ce16778656
3 changed files with 18 additions and 0 deletions

View File

@ -506,6 +506,12 @@ pub mod tests {
{
let mut file = File::open(&pack_path).unwrap();
file.read_to_end(&mut buf).unwrap();
// After being closed the datapacks are read-only. Since the next part of the test
// corrupt it, let's make it writable.
let mut perms = file.metadata().unwrap().permissions();
perms.set_readonly(false);
file.set_permissions(perms).unwrap();
}
buf[0] = 0;
OpenOptions::new()

View File

@ -76,6 +76,12 @@ impl MutableDataPack {
let data_filepath = base_filepath.with_extension("datapack");
let index_filepath = base_filepath.with_extension("dataidx");
let mut perms = self.data_file.as_file().metadata()?.permissions();
perms.set_readonly(true);
self.data_file.as_file().set_permissions(perms.clone())?;
index_file.as_file().set_permissions(perms)?;
self.data_file.persist(&data_filepath)?;
index_file.persist(&index_filepath)?;
Ok(base_filepath)

View File

@ -109,6 +109,12 @@ impl MutableHistoryPack {
let data_filepath = base_filepath.with_extension("histpack");
let index_filepath = base_filepath.with_extension("histidx");
let mut perms = data_file.as_file().metadata()?.permissions();
perms.set_readonly(true);
data_file.as_file().set_permissions(perms.clone())?;
index_file.as_file().set_permissions(perms)?;
data_file.persist(&data_filepath)?;
index_file.persist(&index_filepath)?;
Ok(base_filepath)