fix(content): persist provider aliases after matching
This commit is contained in:
1 parent
ae7a2de19d
commit
63b4adaca8
2 files changed
+142
-72
No files matched your search
@@ -249,7 +249,12 @@ fn save_reconciled_manifest(
|
||||
.record(&record.relative_path)
|
||||
.is_some_and(|existing| {
|
||||
existing.fingerprint == record.fingerprint
|
||||
&& matches!(existing.resolution, Resolution::Resolved { .. })
|
||||
&& existing.resolved_project().is_some_and(|current| {
|
||||
record.resolved_project().is_none_or(|resolved| {
|
||||
current.provider != resolved.provider
|
||||
|| current.project_id != resolved.project_id
|
||||
})
|
||||
})
|
||||
});
|
||||
if !keep_resolved {
|
||||
current.upsert(record);
|
||||
@@ -396,23 +401,27 @@ fn reconcile_inventory(
|
||||
.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)?;
|
||||
}
|
||||
record.resolution = Resolution::Pending;
|
||||
if !is_directory
|
||||
&& !oversized
|
||||
&& provider_unchecked
|
||||
&& record.fingerprint.hash("curseforge").is_none()
|
||||
{
|
||||
record.fingerprint = fingerprint(&path)?;
|
||||
}
|
||||
let should_query = !is_directory
|
||||
&& !oversized
|
||||
&& match &record.resolution {
|
||||
Resolution::Pending => true,
|
||||
Resolution::Unmatched { checked_at, .. } => {
|
||||
now.saturating_sub(*checked_at) >= retry_seconds
|
||||
}
|
||||
Resolution::Resolved { .. } | Resolution::Ambiguous { .. } => false,
|
||||
};
|
||||
&& (provider_unchecked
|
||||
|| match &record.resolution {
|
||||
Resolution::Pending => true,
|
||||
Resolution::Unmatched { checked_at, .. } => {
|
||||
now.saturating_sub(*checked_at) >= retry_seconds
|
||||
}
|
||||
Resolution::Resolved { .. } | Resolution::Ambiguous { .. } => false,
|
||||
});
|
||||
if should_query {
|
||||
record.resolution = Resolution::Pending;
|
||||
if !matches!(&record.resolution, Resolution::Resolved { .. }) {
|
||||
record.resolution = Resolution::Pending;
|
||||
}
|
||||
queries.push(FingerprintQuery {
|
||||
key: relative_path.to_string_lossy().into_owned(),
|
||||
kind,
|
||||
@@ -501,46 +510,73 @@ async fn resolve_queries(
|
||||
if !query_keys.contains(key.as_ref()) {
|
||||
continue;
|
||||
}
|
||||
let candidates = matches.remove(key.as_ref()).unwrap_or_default();
|
||||
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(),
|
||||
},
|
||||
candidates
|
||||
.iter()
|
||||
.filter(|candidate| *candidate != project)
|
||||
.cloned()
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
(Resolution::Ambiguous { candidates }, Vec::new())
|
||||
}
|
||||
let installed = record.resolved_project().cloned();
|
||||
let mut candidates = matches.remove(key.as_ref()).unwrap_or_default();
|
||||
for alias in &record.provider_aliases {
|
||||
if !candidates.iter().any(|candidate| {
|
||||
candidate.provider == alias.provider && candidate.project_id == alias.project_id
|
||||
}) {
|
||||
candidates.push(alias.clone());
|
||||
}
|
||||
}
|
||||
let (resolution, aliases) = if let Some(installed) = installed {
|
||||
let project = candidates
|
||||
.iter()
|
||||
.find(|candidate| {
|
||||
candidate.provider == installed.provider
|
||||
&& candidate.project_id == installed.project_id
|
||||
})
|
||||
.cloned()
|
||||
.unwrap_or(installed);
|
||||
candidates.retain(|candidate| {
|
||||
candidate.provider != project.provider || candidate.project_id != project.project_id
|
||||
});
|
||||
(Resolution::Resolved { project }, candidates)
|
||||
} else {
|
||||
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(),
|
||||
},
|
||||
candidates
|
||||
.iter()
|
||||
.filter(|candidate| *candidate != project)
|
||||
.cloned()
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
(Resolution::Ambiguous { candidates }, Vec::new())
|
||||
}
|
||||
}
|
||||
_ => (Resolution::Ambiguous { candidates }, Vec::new()),
|
||||
}
|
||||
_ => (Resolution::Ambiguous { candidates }, Vec::new()),
|
||||
};
|
||||
record.resolution = resolution;
|
||||
record.provider_aliases = aliases;
|
||||
record.provider_checks.clone_from(&checked);
|
||||
for provider in &checked {
|
||||
if !record.provider_checks.contains(provider) {
|
||||
record.provider_checks.push(provider.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,6 +8,31 @@ impl InventoryProgress for NoopProgress {
|
||||
fn set_progress(&self, _current: u64, _total: u64) {}
|
||||
}
|
||||
|
||||
fn resolved_record() -> ContentFileRecord {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
fn job(name: &str) -> ReconcileJob {
|
||||
ReconcileJob {
|
||||
instance: InstanceConfig {
|
||||
@@ -105,28 +130,7 @@ fn unchanged_saved_index_reuses_fingerprint_and_skips_provider_query() {
|
||||
|
||||
#[test]
|
||||
fn newly_configured_provider_retries_an_unmatched_record() {
|
||||
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,
|
||||
};
|
||||
let mut record = resolved_record();
|
||||
|
||||
assert!(provider_was_not_checked(&record, "curseforge"));
|
||||
assert!(!provider_was_not_checked(&record, "modrinth"));
|
||||
@@ -134,6 +138,36 @@ fn newly_configured_provider_retries_an_unmatched_record() {
|
||||
assert!(!provider_was_not_checked(&record, "curseforge"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reconciliation_saves_provider_aliases_for_an_existing_resolution() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let manifest_path = temp.path().join("manifest.json");
|
||||
let current = ContentManifest {
|
||||
version: 1,
|
||||
files: vec![resolved_record()],
|
||||
};
|
||||
current.save(&manifest_path).unwrap();
|
||||
|
||||
let mut enriched = resolved_record();
|
||||
enriched.provider_aliases.push(ProviderProject {
|
||||
provider: "curseforge".to_owned(),
|
||||
project_id: "42".to_owned(),
|
||||
version_id: "84".to_owned(),
|
||||
});
|
||||
enriched.provider_checks = vec!["modrinth".to_owned(), "curseforge".to_owned()];
|
||||
let saved = save_reconciled_manifest(
|
||||
&manifest_path,
|
||||
&temp.path().join("minecraft"),
|
||||
ContentManifest {
|
||||
version: 1,
|
||||
files: vec![enriched.clone()],
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(saved.files, vec![enriched]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn directory_packs_are_indexed_without_provider_queries() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user