From bed639961dd2e4a03b78f8668bbd2b4d1e22986a Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 25 Nov 2026 10:23:51 +0000 Subject: [PATCH 1/2] font-store: Windows flushes a copy through a writable handle; tests build and pass on Windows `copy_in` flushed the checked copy through `File::open`, a read-only handle. Windows' FlushFileBuffers needs write access, so every copy failed with "Access is denied" and no family could be made available to all apps there. Tests: `catalog_of` is used only by a unix test, so it is unix-only too (dead code broke the Windows lint build), and the Flatpak host-folder case uses a path under the test root, since `/elsewhere` isn't absolute on Windows. Co-Authored-By: Claude Opus 5.5 --- crates/font-store/src/store/os_fonts.rs | 3 ++- crates/font-store/src/tests.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/font-store/src/store/os_fonts.rs b/crates/font-store/src/store/os_fonts.rs index a12d7e10c..0dceeabbd 100644 --- a/crates/font-store/src/store/os_fonts.rs +++ b/crates/font-store/src/store/os_fonts.rs @@ -880,7 +880,8 @@ fn copy_in(folder: &OsFontFolder, p: &Planned, found: Option<&str>) -> Result<() let _ = std::fs::remove_file(&part); std::fs::copy(&p.source, &part).map_err(io(what()))?; folder.unload(&p.path); - let checked = File::open(&part).and_then(|f| f.sync_all()).map_err(io(what())).and_then(|()| { + // Windows flushes a file only through a handle that can write to it. + let checked = std::fs::OpenOptions::new().write(true).open(&part).and_then(|f| f.sync_all()).map_err(io(what())).and_then(|()| { if file_sha256(&part).as_ref() == Some(&p.sha256) { Ok(()) } else { diff --git a/crates/font-store/src/tests.rs b/crates/font-store/src/tests.rs index db80004eb..8ebfb213a 100644 --- a/crates/font-store/src/tests.rs +++ b/crates/font-store/src/tests.rs @@ -1522,6 +1522,7 @@ mod store { } /// A catalog of the same system as [`shared_store`]'s, to look at what a scan sees. + #[cfg(unix)] fn catalog_of(dir: &Path, root: &Path) -> Catalog { let env = FontEnv { os: Os::Unix, @@ -1704,9 +1705,12 @@ mod store { assert!(with(&[], &flatpak).is_err(), "read only"); info("~/.local/share/fonts;"); assert!(with(&[], &flatpak).is_ok()); - assert!(with(&[("HOST_XDG_DATA_HOME", "/elsewhere")], &flatpak).is_err(), "the grant is for another folder"); + // Absolute on every platform: `/elsewhere` isn't on Windows. + let elsewhere = root.join("elsewhere"); + let host = [("HOST_XDG_DATA_HOME", elsewhere.to_str().unwrap())]; + assert!(with(&host, &flatpak).is_err(), "the grant is for another folder"); info("xdg-data/fonts;"); - assert_eq!(with(&[("HOST_XDG_DATA_HOME", "/elsewhere")], &flatpak), Ok(PathBuf::from("/elsewhere/fonts/Craft"))); + assert_eq!(with(&host, &flatpak), Ok(elsewhere.join("fonts/Craft"))); let _ = std::fs::remove_dir_all(root); } From dd03495de137c59885c8005df6f4717928bd2b2e Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 25 Nov 2026 11:51:58 +0000 Subject: [PATCH 2/2] font-store: write and flush an OS copy through one writable handle, so a read-only store file still copies std::fs::copy gave the copy the store file's permissions, and the writable open for the flush then failed on a read-only one. Trial read_only_store_files_are_made_available. Co-Authored-By: Claude Opus 5.5 --- crates/font-store/src/store/os_fonts.rs | 25 ++++++++++++++++--------- crates/font-store/src/tests.rs | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/crates/font-store/src/store/os_fonts.rs b/crates/font-store/src/store/os_fonts.rs index 0dceeabbd..2fd7af81d 100644 --- a/crates/font-store/src/store/os_fonts.rs +++ b/crates/font-store/src/store/os_fonts.rs @@ -878,16 +878,23 @@ fn copy_in(folder: &OsFontFolder, p: &Planned, found: Option<&str>) -> Result<() } let part = aside(&p.path, "part"); let _ = std::fs::remove_file(&part); - std::fs::copy(&p.source, &part).map_err(io(what()))?; - folder.unload(&p.path); - // Windows flushes a file only through a handle that can write to it. - let checked = std::fs::OpenOptions::new().write(true).open(&part).and_then(|f| f.sync_all()).map_err(io(what())).and_then(|()| { - if file_sha256(&part).as_ref() == Some(&p.sha256) { - Ok(()) - } else { - Err(Error::Verify { file: p.store_file.clone(), error: VerifyError::Sha256 }) - } + // One writable handle writes and flushes the copy: Windows flushes only through a handle that can write, and the + // copy doesn't take the source's permissions (`std::fs::copy` would), so a read-only store file still copies. + let copied = File::open(&p.source).and_then(|mut source| { + let mut copy = File::create(&part)?; + std::io::copy(&mut source, &mut copy)?; + copy.sync_all() }); + if let Err(e) = copied { + let _ = std::fs::remove_file(&part); + return Err(io(what())(e)); + } + folder.unload(&p.path); + let checked = if file_sha256(&part).as_ref() == Some(&p.sha256) { + Ok(()) + } else { + Err(Error::Verify { file: p.store_file.clone(), error: VerifyError::Sha256 }) + }; if let Err(e) = checked.and_then(|()| publish(&part, p, found)) { let _ = std::fs::remove_file(&part); return Err(e); diff --git a/crates/font-store/src/tests.rs b/crates/font-store/src/tests.rs index 8ebfb213a..484835b69 100644 --- a/crates/font-store/src/tests.rs +++ b/crates/font-store/src/tests.rs @@ -1421,6 +1421,28 @@ mod store { assert_eq!(files[0]["postscript"], json!(["TestSans-Bold"])); } + #[test] + fn read_only_store_files_are_made_available() { + let server = Server::start(); + server.serve_fixture(&fixture()); + let (store, dir, root, shared) = shared_store(&server, "os-fonts-read-only"); + let set_read_only = |read_only: bool| { + for name in entries(&dir.join("testsans")) { + let path = dir.join("testsans").join(name); + let mut permissions = std::fs::metadata(&path).unwrap().permissions(); + permissions.set_readonly(read_only); + std::fs::set_permissions(&path, permissions).unwrap(); + } + }; + set_read_only(true); + let copies = store.make_available(GOOGLE_FONTS, "Test Sans"); + set_read_only(false); + assert_eq!(copies.unwrap().len(), 3, "a read-only store file still copies"); + assert!(entries(&shared.join("testsans")).iter().all(|name| !name.starts_with('.')), "no copy is left aside"); + let _ = std::fs::remove_dir_all(dir); + let _ = std::fs::remove_dir_all(root); + } + #[test] fn a_family_made_available_to_all_apps_is_withdrawn_exactly() { let server = Server::start();