font-store: list a deleted copy as pending so start-up copies it again

This commit is contained in:
aiongg
2026-11-25 03:30:14 +00:00
parent beb4520281
commit 94db2b1ce6
2 changed files with 18 additions and 8 deletions
+3 -8
View File
@@ -517,8 +517,8 @@ impl FontStore {
/// The store files of an available family that have no copy in the OS folder yet, by their
/// names in its folder: styles installed since (an agent's install doesn't copy them), or
/// files whose copy is older than the store's, or whose identical system file is gone. Empty
/// for a family that isn't available.
/// files whose copy is older than the store's, or whose copy or identical system file is gone
/// (the user deleted it, say). Empty for a family that isn't available.
pub fn pending_files(&self, source: &str, name: &str) -> Vec<String> {
let Some(ledger) = self.cached_ledger() else { return Vec::new() };
let Some(listed) = ledger.family(source, name) else { return Vec::new() };
@@ -526,12 +526,7 @@ impl FontStore {
family
.files
.iter()
.filter(|f| {
!listed
.files
.iter()
.any(|x| x.store_file == f.name && x.sha256 == f.sha256 && (x.mechanism == Mechanism::Copy || std::fs::metadata(&x.path).is_ok()))
})
.filter(|f| !listed.files.iter().any(|x| x.store_file == f.name && x.sha256 == f.sha256 && std::fs::metadata(&x.path).is_ok()))
.map(|f| f.name.clone())
.collect()
}
+15
View File
@@ -1625,6 +1625,21 @@ mod store {
let _ = std::fs::remove_dir_all(root);
}
#[test]
fn a_deleted_copy_is_pending_and_copied_again() {
let server = Server::start();
server.serve_fixture(&fixture());
let (store, dir, root, _shared) = shared_store(&server, "os-fonts-deleted");
let copies = store.make_available(GOOGLE_FONTS, "Test Sans").unwrap();
std::fs::remove_file(&copies[0]).unwrap();
assert_eq!(store.pending_files(GOOGLE_FONTS, "Test Sans").len(), 1);
assert_eq!(store.make_available(GOOGLE_FONTS, "Test Sans").unwrap(), copies);
assert!(copies.iter().all(|c| c.is_file()));
assert!(store.pending_files(GOOGLE_FONTS, "Test Sans").is_empty());
let _ = std::fs::remove_dir_all(dir);
let _ = std::fs::remove_dir_all(root);
}
#[test]
fn an_agent_never_changes_the_os_font_folder() {
let server = Server::start();