Skip to content

Commit 51f6b71

Browse files
authored
Merge pull request #55 from alexander-bauer/readonly-bundles
Make cached bundle files readonly
2 parents d8f9e59 + b14c8ca commit 51f6b71

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/io/local_cache.rs

Lines changed: 12 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,18 @@ 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+
// XXX: It would be better to set these using the already-open file handle owned by the
311+
// tempfile, but mkstemp doesn't give us access.
312+
let mut perms = match fs::metadata(&final_path) {
313+
Ok(p) => p,
314+
Err(e) => return OpenResult::Err(e.into()),
315+
}.permissions();
316+
perms.set_readonly(true);
317+
if let Err(e) = fs::set_permissions(&final_path, perms) {
318+
return OpenResult::Err(e.into());
319+
}
320+
311321
// And finally add a record of this file to our manifest. Note that
312322
// we're opening and closing this file every time we load a new file;
313323
// not so efficient, but whatever.

0 commit comments

Comments
 (0)