Scripts: an XMP sidecar update flushes the packet first and goes through on volumes without Unix permissions

- closeFile() flushes the temporary file to the disk with vectorcraft_format::sync_file before it
  takes the sidecar's name, as a saved document's temporary file is flushed.
- Keeping the sidecar's permissions is best effort, as in write_atomic: a volume that refuses Unix
  permissions (SMB, FAT) no longer makes every update throw "Script file could not be written".
- docs/mcp.md says both.
This commit is contained in:
dotCooCoo committed 2026-11-22 16:52:35 -08:00
1 parent 06d430e4bd
commit a0cc0230b0
2 files changed
+13 -5

No files matched your search

+11 -4
View File
@@ -1995,17 +1995,24 @@ fn xmp_write(host: &Host, a: &[Data]) -> Result<Data, HostError> {
let mode = std::os::unix::fs::PermissionsExt::mode(&out.metadata()?.permissions());
XMP_TEMP_MODE.with(|m| m.set(Some(mode)));
}
std::io::Write::write_all(&mut out, &packet)
std::io::Write::write_all(&mut out, &packet)?;
// The packet is on the disk before it takes the sidecar's name, as a saved document's is.
#[cfg(not(target_arch = "wasm32"))]
vectorcraft_format::sync_file(&out)?;
Ok(())
};
let r = write_temp();
drop(out);
// The replacement keeps the sidecar's permission bits, group and (Linux) access ACL, or is
// readable by its owner alone, as a saved document is (`vectorcraft_format::keep_permissions`).
// On Windows the only permission is the read-only attribute, and a read-only temporary file
// could not be removed after a failed rename. The web build has no such files. Permission
// bits that cannot be set fail the write, and the sidecar stays as it was.
// could not be removed after a failed rename. The web build has no such files. Keeping them
// is best effort, as for a saved document: a volume without Unix permissions (SMB, FAT) refuses them, and the
// update still goes through.
#[cfg(not(target_arch = "wasm32"))]
let r = r.and_then(|()| vectorcraft_format::keep_permissions(&target, &temp));
if r.is_ok() {
let _ = vectorcraft_format::keep_permissions(&target, &temp);
}
let r = r.and_then(|()| std::fs::rename(&temp, &target)).inspect_err(|_| {
let _ = std::fs::remove_file(&temp);
});
+2 -1
View File
@@ -3086,7 +3086,8 @@ rules for these objects:
UTF-8 through a temporary file in the same folder when the script may write there, otherwise straight to the file;
when no temporary name is free, nothing is written. On Unix the replacement keeps the file's permission bits, group
and (on Linux) access ACL, as a saved document does, and is readable by its owner alone where the group or the ACL
cannot be kept. With `XMPConst.CLOSE_UPDATE_SAFELY`, `closeFile()` writes only
cannot be kept; on a volume that refuses Unix permissions (SMB, FAT) the update still goes through. The packet is flushed to the disk before the temporary file takes the file's
name. With `XMPConst.CLOSE_UPDATE_SAFELY`, `closeFile()` writes only
through a temporary file, and where the script may not make one it throws `Script file could not be written` and
leaves the file as it is. A failed write throws and keeps the file open with its packet. While an open `File` of the same file holds changes it has not written, `closeFile()` throws
`Script file could not be written` and the `File` keeps its changes. `getXMP`, `getPacketInfo`, `getFileInfo` and `canPutXMP` are available. An `XMPFile` is open only in the