mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Scripts: a sidecar XMPFile replaces keeps its Unix permission bits
closeFile() writes a sidecar through a new temporary file and renames it over the sidecar, so a 0600 sidecar became 0644 under a 022 umask. The temporary file now takes the sidecar's permission bits before the rename, as File.copy does for its target. Test: a_replaced_sidecar_keeps_its_permissions (Unix only) in crates/engine/src/tests/script_xmp.rs.
This commit is contained in:
1 parent
84acd52710
commit
58dab25cc6
2 files changed
+35
-3
No files matched your search
@@ -1981,9 +1981,16 @@ fn xmp_write(host: &Host, a: &[Data]) -> Result<Data, HostError> {
|
||||
};
|
||||
let r = write_temp();
|
||||
drop(out);
|
||||
let r = r.and_then(|()| std::fs::rename(&temp, &target)).inspect_err(|_| {
|
||||
let _ = std::fs::remove_file(&temp);
|
||||
});
|
||||
// The replacement keeps the sidecar's permission bits. On Windows the only permission is the
|
||||
// read-only attribute, and a read-only temporary file could not be removed after a failed
|
||||
// rename.
|
||||
let permissions = if cfg!(unix) { std::fs::metadata(&target).map(|m| m.permissions()).ok() } else { None };
|
||||
let r = r
|
||||
.and_then(|()| permissions.map_or(Ok(()), |p| std::fs::set_permissions(&temp, p)))
|
||||
.and_then(|()| std::fs::rename(&temp, &target))
|
||||
.inspect_err(|_| {
|
||||
let _ = std::fs::remove_file(&temp);
|
||||
});
|
||||
let changed = r.is_ok();
|
||||
(r, changed)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user