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:
dotCooCoo committed 2026-11-22 08:11:31 -08:00
1 parent 84acd52710
commit 58dab25cc6
2 files changed
+35 -3

No files matched your search

+10 -3
View File
@@ -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 {