From 4a1ac38ac3bf05160bf2deb41695fc90e8d80405 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 3 Dec 2026 02:59:58 -0800 Subject: [PATCH] Scripts: a Linux folder whose casefold flag can't be read is taken as casefolded When the folder can't be opened or `FS_IOC_GETFLAGS` fails, `casefolded` returned false, so `imageCapture` treated names that differ only in their normalization form as two files and could write over a source document. It now returns false only when the flags are read and the flag is clear. --- crates/engine/src/script/dom/raster_capture.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/script/dom/raster_capture.rs b/crates/engine/src/script/dom/raster_capture.rs index b7385a6b94..f067b430d4 100644 --- a/crates/engine/src/script/dom/raster_capture.rs +++ b/crates/engine/src/script/dom/raster_capture.rs @@ -348,7 +348,7 @@ fn same_file(a: &Placed, b: &Placed) -> bool { /// names ignore the form when that finds the same entry. With no such entry, names ignore the form /// on macOS, whose volumes (APFS and HFS+) look names up that way, and on Linux in a folder that /// carries the casefold inode flag ([`casefolded`]): ext4 and f2fs casefolding also ignores the -/// form. Elsewhere, and on Linux when the flag can't be read, names keep the form. +/// form, as they are taken to when the flag can't be read. Elsewhere names keep the form. fn ignores_normalization(folder: &std::path::Path) -> bool { use unicode_normalization::UnicodeNormalization; for entry in std::fs::read_dir(folder).into_iter().flatten().flatten().take(256) { @@ -374,10 +374,11 @@ fn ignores_normalization(folder: &std::path::Path) -> bool { const FS_CASEFOLD_FL: u32 = 0x4000_0000; /// Whether the Linux folder `folder` carries the casefold inode flag, read with -/// `FS_IOC_GETFLAGS`. `false` when the folder can't be opened or its flags can't be read. +/// `FS_IOC_GETFLAGS`. `true` when the folder can't be opened or its flags can't be read: `false` +/// only when the flags are read and the flag is clear. #[cfg(target_os = "linux")] fn casefolded(folder: &std::path::Path) -> bool { - std::fs::File::open(folder).ok().and_then(|d| rustix::fs::ioctl_getflags(&d).ok()).is_some_and(|f| has_casefold(f.bits())) + std::fs::File::open(folder).ok().and_then(|d| rustix::fs::ioctl_getflags(&d).ok()).is_none_or(|f| has_casefold(f.bits())) } /// Whether the inode flags `bits` include `FS_CASEFOLD_FL`. @@ -680,7 +681,8 @@ mod source_tests { } /// A casefolded folder, which looks a name up in either normalization form, is recognized by - /// its inode flag, and a folder that can't be read is not taken for one. + /// its inode flag. A folder whose flags can't be read is taken for one, so a capture is never + /// written over a source under a name in another normalization form. #[cfg(target_os = "linux")] #[test] fn a_casefolded_folder_is_recognized_by_its_inode_flag() { @@ -689,6 +691,6 @@ mod source_tests { assert!(!has_casefold(0x10)); assert!(!has_casefold(0)); let dir = vectorcraft_testkit::TempDir::new("capture-nfd-missing"); - assert!(!casefolded(&dir.join("missing"))); + assert!(casefolded(&dir.join("missing"))); } }