mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
Merge main into next (font-store: Windows copies, #3467)
This commit is contained in:
@@ -868,15 +868,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);
|
||||
let checked = File::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);
|
||||
|
||||
@@ -904,6 +904,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();
|
||||
@@ -1005,6 +1027,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,
|
||||
@@ -1187,9 +1210,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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user