Skip to content

Commit c1edbad

Browse files
Make cache files readonly
- After moving new cache files to their final destination, set their permissions to have `readonly` set `true`. - This uses `fs::set_permissions` rather than the suggested ``fs::File::set_permissions`, because the latter would require the final file to be open. We cannot change the permissions on the tempfile in this way, because `mkstemp::TempFile` doesn't have the same `set_permissions` method. Close #14
1 parent ed3a2d0 commit c1edbad

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/io/local_cache.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ impl<B: IoProvider> LocalCache<B> {
290290
}
291291
}
292292

293-
// XXX MAKE READONLY -- the ideal approach depends on unstable APIs
294-
295293
temp_dest.path().to_owned()
296294
};
297295

@@ -308,6 +306,16 @@ impl<B: IoProvider> LocalCache<B> {
308306
return OpenResult::Err(e.into());
309307
}
310308

309+
// Make the file readonly once it's at its final path.
310+
let mut perms = match fs::metadata(&final_path) {
311+
Ok(p) => p,
312+
Err(e) => return OpenResult::Err(e.into()),
313+
}.permissions();
314+
perms.set_readonly(true);
315+
if let Err(e) = fs::set_permissions(&final_path, perms) {
316+
return OpenResult::Err(e.into());
317+
}
318+
311319
// And finally add a record of this file to our manifest. Note that
312320
// we're opening and closing this file every time we load a new file;
313321
// not so efficient, but whatever.

0 commit comments

Comments
 (0)