fix(content): refresh installed provider metadata

This commit is contained in:
objz committed 2026-08-05 15:25:07 +02:00
1 parent 2d0007de52
commit ae7a2de19d
17 files changed
+310 -103

No files matched your search

+1
View File
@@ -337,6 +337,7 @@ fn build_records(
project: item.identity(),
},
provider_aliases: item.provider_aliases.clone(),
provider_checks: vec![item.provider.clone()],
required_dependencies: item.required_dependencies.clone(),
automatic_dependency: item.automatic_dependency,
cleanup_eligible: item.cleanup_eligible,
+2
View File
@@ -90,6 +90,8 @@ pub struct ContentFileRecord {
#[serde(default)]
pub provider_aliases: Vec<ProviderProject>,
#[serde(default)]
pub provider_checks: Vec<String>,
#[serde(default)]
pub required_dependencies: Vec<ProviderProject>,
#[serde(default)]
pub automatic_dependency: bool,
+74 -30
View File
@@ -15,6 +15,7 @@ use crate::storage::InstancePaths;
#[derive(Debug)]
pub struct ReconcileResult {
pub instance_name: String,
pub instance_created: chrono::DateTime<chrono::Utc>,
pub manifest: ContentManifest,
pub error: Option<String>,
}
@@ -32,17 +33,17 @@ struct ReconcileJob {
#[derive(Default)]
struct ReconcileCoordinator {
queue: VecDeque<ReconcileJob>,
scheduled: HashSet<String>,
rerun: HashSet<String>,
scheduled: HashSet<(String, chrono::DateTime<chrono::Utc>)>,
rerun: HashSet<(String, chrono::DateTime<chrono::Utc>)>,
worker_running: bool,
}
impl ReconcileCoordinator {
fn enqueue(&mut self, job: ReconcileJob, rerun_if_scheduled: bool) -> bool {
let instance_name = job.instance.name.clone();
if !self.scheduled.insert(instance_name.clone()) {
let instance = (job.instance.name.clone(), job.instance.created);
if !self.scheduled.insert(instance.clone()) {
if rerun_if_scheduled {
self.rerun.insert(instance_name);
self.rerun.insert(instance);
}
return false;
}
@@ -112,18 +113,21 @@ async fn reconcile_worker() {
}
}
};
let instance_name = job.instance.name.clone();
let instance = (job.instance.name.clone(), job.instance.created);
let rerun_job = job.clone();
let result = reconcile(job, &task).await;
if let Ok(mut results) = PENDING_RECONCILIATIONS.lock() {
results.retain(|pending| pending.instance_name != instance_name);
results.retain(|pending| {
(pending.instance_name.as_str(), pending.instance_created)
!= (instance.0.as_str(), instance.1)
});
results.push(result);
}
if let Ok(mut coordinator) = RECONCILE_COORDINATOR.lock() {
if coordinator.rerun.remove(&instance_name) {
if coordinator.rerun.remove(&instance) {
coordinator.queue.push_back(rerun_job);
} else {
coordinator.scheduled.remove(&instance_name);
coordinator.scheduled.remove(&instance);
}
}
crate::feedback::request_redraw();
@@ -137,6 +141,7 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
client,
} = job;
let instance_name = instance.name;
let instance_created = instance.created;
task.set_action(format!("Checking content for {instance_name}"));
task.set_sub_action("Reading saved content index");
task.set_progress(0, 1);
@@ -183,11 +188,13 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
) {
Ok(manifest) => ReconcileResult {
instance_name,
instance_created,
manifest,
error: None,
},
Err(error) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
@@ -200,6 +207,7 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
);
ReconcileResult {
instance_name,
instance_created,
manifest: saved.unwrap_or_default(),
error: Some(error.to_string()),
}
@@ -208,11 +216,13 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
}
Ok(Err(error)) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
Err(error) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
@@ -330,6 +340,7 @@ fn reconcile_inventory(
providers: Vec::new(),
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -351,6 +362,7 @@ fn reconcile_inventory(
providers: Vec::new(),
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -363,6 +375,7 @@ fn reconcile_inventory(
fingerprint: fingerprint(&path)?,
resolution: Resolution::Pending,
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -377,9 +390,13 @@ fn reconcile_inventory(
providers: Vec::new(),
};
}
let curseforge_unchecked = crate::net::curseforge::api_key().is_some()
&& provider_was_not_checked(&record.resolution, "curseforge");
if !is_directory && !oversized && curseforge_unchecked {
let provider_unchecked = ["modrinth", "curseforge"].into_iter().any(|provider| {
crate::config::SETTINGS
.content
.discovery_provider_enabled(provider)
&& provider_was_not_checked(&record, provider)
});
if !is_directory && !oversized && provider_unchecked {
if record.fingerprint.hash("curseforge").is_none() {
record.fingerprint = fingerprint(&path)?;
}
@@ -408,12 +425,23 @@ fn reconcile_inventory(
Ok(Inventory { manifest, queries })
}
fn provider_was_not_checked(resolution: &Resolution, provider: &str) -> bool {
matches!(
resolution,
fn provider_was_not_checked(record: &ContentFileRecord, provider: &str) -> bool {
let identified = record
.resolved_project()
.into_iter()
.chain(record.provider_aliases.iter())
.any(|project| project.provider == provider);
let checked_as_unmatched = matches!(
&record.resolution,
Resolution::Unmatched { providers, .. }
if !providers.iter().any(|checked| checked == provider)
)
if providers.iter().any(|checked| checked == provider)
);
!identified
&& !checked_as_unmatched
&& !record
.provider_checks
.iter()
.any(|checked| checked == provider)
}
async fn resolve_queries(
@@ -474,29 +502,45 @@ async fn resolve_queries(
continue;
}
let candidates = matches.remove(key.as_ref()).unwrap_or_default();
record.resolution = match candidates.as_slice() {
[] => Resolution::Unmatched {
checked_at,
providers: checked.clone(),
},
[project] => Resolution::Resolved {
project: project.clone(),
},
let (resolution, aliases) = match candidates.as_slice() {
[] => (
Resolution::Unmatched {
checked_at,
providers: checked.clone(),
},
Vec::new(),
),
[project] => (
Resolution::Resolved {
project: project.clone(),
},
Vec::new(),
),
_ if !crate::config::SETTINGS.content.ask_on_provider_conflict => {
let preferred = crate::config::SETTINGS.content.preferred_provider();
if let Some(project) = candidates
.iter()
.find(|project| project.provider == preferred)
{
Resolution::Resolved {
project: project.clone(),
}
(
Resolution::Resolved {
project: project.clone(),
},
candidates
.iter()
.filter(|candidate| *candidate != project)
.cloned()
.collect(),
)
} else {
Resolution::Ambiguous { candidates }
(Resolution::Ambiguous { candidates }, Vec::new())
}
}
_ => Resolution::Ambiguous { candidates },
_ => (Resolution::Ambiguous { candidates }, Vec::new()),
};
record.resolution = resolution;
record.provider_aliases = aliases;
record.provider_checks.clone_from(&checked);
}
Ok(())
}
+4
View File
@@ -35,6 +35,7 @@ pub struct UpdateCheckFailure {
pub struct PendingUpdateSnapshot {
pub instance_name: String,
pub instance_created: chrono::DateTime<chrono::Utc>,
pub snapshot: UpdateSnapshot,
}
@@ -106,6 +107,7 @@ pub fn spawn(instance: InstanceConfig, manifest: ContentManifest, path: std::pat
if let Ok(mut pending) = PENDING_UPDATE_SNAPSHOTS.lock() {
pending.push(PendingUpdateSnapshot {
instance_name: instance.name,
instance_created: instance.created,
snapshot,
});
crate::feedback::request_redraw();
@@ -419,6 +421,7 @@ mod tests {
},
resolution: crate::instance::Resolution::Resolved { project },
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -454,6 +457,7 @@ mod tests {
project: installed.clone(),
},
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: true,
cleanup_eligible: true,
+1
View File
@@ -403,6 +403,7 @@ fn seed_content_manifest(
},
},
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -278,6 +278,7 @@ fn installed_record(project_id: &str, version_id: &str, enabled: bool) -> Conten
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -823,6 +824,7 @@ async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -946,6 +948,7 @@ async fn installed_incompatible_projects_block_the_plan() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
+3
View File
@@ -36,6 +36,7 @@ fn manifest_round_trip_and_lookup_are_exact() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -89,6 +90,7 @@ fn renaming_a_record_preserves_its_resolution() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -129,6 +131,7 @@ fn managed_record(
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies,
automatic_dependency,
cleanup_eligible: automatic_dependency,
+41 -8
View File
@@ -15,7 +15,7 @@ fn job(name: &str) -> ReconcileJob {
game_version: "1.21.1".to_owned(),
loader: crate::instance::ModLoader::Fabric,
loader_version: None,
created: chrono::Utc::now(),
created: chrono::DateTime::UNIX_EPOCH,
last_played: None,
java_path: None,
memory_max: None,
@@ -33,17 +33,30 @@ fn job(name: &str) -> ReconcileJob {
#[test]
fn coordinator_queues_instances_once_and_preserves_order() {
let mut coordinator = ReconcileCoordinator::default();
let one = ("one".to_owned(), chrono::DateTime::UNIX_EPOCH);
assert!(coordinator.enqueue(job("one"), false));
assert!(!coordinator.enqueue(job("two"), false));
assert!(!coordinator.enqueue(job("one"), false));
assert!(!coordinator.rerun.contains("one"));
assert!(!coordinator.rerun.contains(&one));
assert!(!coordinator.enqueue(job("one"), true));
assert_eq!(coordinator.queue.len(), 2);
assert!(coordinator.rerun.contains("one"));
assert!(coordinator.rerun.contains(&one));
assert_eq!(coordinator.queue.pop_front().unwrap().instance.name, "one");
assert_eq!(coordinator.queue.pop_front().unwrap().instance.name, "two");
}
#[test]
fn coordinator_does_not_merge_recreated_instances_with_the_same_name() {
let mut coordinator = ReconcileCoordinator::default();
let first = job("same");
let mut recreated = job("same");
recreated.instance.created += chrono::TimeDelta::seconds(1);
assert!(coordinator.enqueue(first, false));
assert!(!coordinator.enqueue(recreated, false));
assert_eq!(coordinator.queue.len(), 2);
}
#[test]
fn oversized_content_is_kept_without_hashing_or_provider_query() {
let temp = tempfile::tempdir().unwrap();
@@ -92,13 +105,33 @@ fn unchanged_saved_index_reuses_fingerprint_and_skips_provider_query() {
#[test]
fn newly_configured_provider_retries_an_unmatched_record() {
let resolution = Resolution::Unmatched {
checked_at: chrono::Utc::now().timestamp(),
providers: vec!["modrinth".to_owned()],
let mut record = ContentFileRecord {
relative_path: PathBuf::from("mods/example.jar"),
kind: ContentKind::Mod,
enabled: true,
fingerprint: FileFingerprint {
size: 1,
modified_ns: 1,
hashes: Default::default(),
},
resolution: Resolution::Resolved {
project: ProviderProject {
provider: "modrinth".to_owned(),
project_id: "example".to_owned(),
version_id: "1".to_owned(),
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
};
assert!(provider_was_not_checked(&resolution, "curseforge"));
assert!(!provider_was_not_checked(&resolution, "modrinth"));
assert!(provider_was_not_checked(&record, "curseforge"));
assert!(!provider_was_not_checked(&record, "modrinth"));
record.provider_checks.push("curseforge".to_owned());
assert!(!provider_was_not_checked(&record, "curseforge"));
}
#[test]