From a0cc0230b034809149c9945e183e0020caf0f3c3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 16:52:35 -0800 Subject: [PATCH] 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. --- crates/engine/src/script/files.rs | 15 +++++++++++---- docs/mcp.md | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/script/files.rs b/crates/engine/src/script/files.rs index d0de6896c7..762dae099a 100644 --- a/crates/engine/src/script/files.rs +++ b/crates/engine/src/script/files.rs @@ -1995,17 +1995,24 @@ fn xmp_write(host: &Host, a: &[Data]) -> Result { 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); }); diff --git a/docs/mcp.md b/docs/mcp.md index d365ca743b..5fd06c6901 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -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