fix(content): resolve selected updates together
This commit is contained in:
1 parent
bfd8be6abe
commit
e9ad30dc29
3 files changed
+161
-14
No files matched your search
@@ -613,7 +613,17 @@ pub fn merge(plans: Vec<DependencyPlan>) -> Result<DependencyPlan, NetError> {
|
|||||||
existing.required_dependencies.push(dependency);
|
existing.required_dependencies.push(dependency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for alias in item.provider_aliases {
|
||||||
|
if !existing.provider_aliases.contains(&alias) {
|
||||||
|
existing.provider_aliases.push(alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
if root && !*existing_root {
|
if root && !*existing_root {
|
||||||
|
existing.title = item.title;
|
||||||
|
if item.installed_path.is_some() {
|
||||||
|
existing.installed_path = item.installed_path;
|
||||||
|
}
|
||||||
|
existing.replacement |= item.replacement;
|
||||||
existing.automatic_dependency = false;
|
existing.automatic_dependency = false;
|
||||||
existing.cleanup_eligible = false;
|
existing.cleanup_eligible = false;
|
||||||
*existing_root = true;
|
*existing_root = true;
|
||||||
|
|||||||
+108
-14
@@ -239,6 +239,7 @@ pub async fn plan_bulk(
|
|||||||
let registry = crate::instance::content::provider::ProviderRegistry::configured(
|
let registry = crate::instance::content::provider::ProviderRegistry::configured(
|
||||||
crate::net::HttpClient::new(),
|
crate::net::HttpClient::new(),
|
||||||
);
|
);
|
||||||
|
let projected_manifest = project_updates(manifest, minecraft_dir, &requests);
|
||||||
let mut accepted = Vec::new();
|
let mut accepted = Vec::new();
|
||||||
let mut roots = Vec::new();
|
let mut roots = Vec::new();
|
||||||
for request in requests {
|
for request in requests {
|
||||||
@@ -252,20 +253,35 @@ pub async fn plan_bulk(
|
|||||||
target_world: request.target_world.clone(),
|
target_world: request.target_world.clone(),
|
||||||
force_reinstall: false,
|
force_reinstall: false,
|
||||||
};
|
};
|
||||||
let plan =
|
let mut resolution_manifest = projected_manifest.clone();
|
||||||
match super::dependencies::resolve(®istry, manifest, minecraft_dir, instance, root)
|
if let Ok(relative_path) = request.installed_path.strip_prefix(minecraft_dir)
|
||||||
.await
|
&& let Some(current) = manifest.record(relative_path)
|
||||||
{
|
&& let Some(projected) = resolution_manifest
|
||||||
Ok(plan) => plan,
|
.files
|
||||||
Err(error) => {
|
.iter_mut()
|
||||||
conflicts.push(UpdateConflict {
|
.find(|record| record.relative_path == relative_path)
|
||||||
title: request.title,
|
{
|
||||||
installed_path: request.installed_path,
|
projected.resolution = current.resolution.clone();
|
||||||
reason: error.to_string(),
|
}
|
||||||
});
|
let plan = match super::dependencies::resolve(
|
||||||
continue;
|
®istry,
|
||||||
}
|
&resolution_manifest,
|
||||||
};
|
minecraft_dir,
|
||||||
|
instance,
|
||||||
|
root,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(plan) => plan,
|
||||||
|
Err(error) => {
|
||||||
|
conflicts.push(UpdateConflict {
|
||||||
|
title: request.title,
|
||||||
|
installed_path: request.installed_path,
|
||||||
|
reason: error.to_string(),
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut proposed = accepted.clone();
|
let mut proposed = accepted.clone();
|
||||||
proposed.push(plan.clone());
|
proposed.push(plan.clone());
|
||||||
if let Err(error) = super::dependencies::merge(proposed) {
|
if let Err(error) = super::dependencies::merge(proposed) {
|
||||||
@@ -298,6 +314,34 @@ pub async fn plan_bulk(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn project_updates(
|
||||||
|
manifest: &ContentManifest,
|
||||||
|
minecraft_dir: &std::path::Path,
|
||||||
|
requests: &[UpdateRequest],
|
||||||
|
) -> ContentManifest {
|
||||||
|
let mut projected = manifest.clone();
|
||||||
|
for request in requests {
|
||||||
|
let Ok(relative_path) = request.installed_path.strip_prefix(minecraft_dir) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let Some(record) = projected
|
||||||
|
.files
|
||||||
|
.iter_mut()
|
||||||
|
.find(|record| record.relative_path == relative_path)
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
record.resolution = crate::instance::Resolution::Resolved {
|
||||||
|
project: ProviderProject {
|
||||||
|
provider: request.update.installed.provider.clone(),
|
||||||
|
project_id: request.update.installed.project_id.clone(),
|
||||||
|
version_id: request.update.target.id.clone(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
projected
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -387,4 +431,54 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert!(!snapshot.matches_manifest(&manifest));
|
assert!(!snapshot.matches_manifest(&manifest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bulk_planning_projects_other_selected_updates() {
|
||||||
|
let minecraft = std::path::Path::new("/instance/minecraft");
|
||||||
|
let installed = ProviderProject {
|
||||||
|
provider: "modrinth".to_owned(),
|
||||||
|
project_id: "library".to_owned(),
|
||||||
|
version_id: "old".to_owned(),
|
||||||
|
};
|
||||||
|
let mut manifest = ContentManifest::default();
|
||||||
|
manifest.files.push(crate::instance::ContentFileRecord {
|
||||||
|
relative_path: "mods/library.jar".into(),
|
||||||
|
kind: ContentKind::Mod,
|
||||||
|
enabled: true,
|
||||||
|
fingerprint: crate::instance::FileFingerprint {
|
||||||
|
size: 1,
|
||||||
|
modified_ns: 1,
|
||||||
|
hashes: Default::default(),
|
||||||
|
},
|
||||||
|
resolution: crate::instance::Resolution::Resolved {
|
||||||
|
project: installed.clone(),
|
||||||
|
},
|
||||||
|
provider_aliases: Vec::new(),
|
||||||
|
required_dependencies: Vec::new(),
|
||||||
|
automatic_dependency: true,
|
||||||
|
cleanup_eligible: true,
|
||||||
|
});
|
||||||
|
let requests = vec![UpdateRequest {
|
||||||
|
title: "Library".to_owned(),
|
||||||
|
installed_path: minecraft.join("mods/library.jar"),
|
||||||
|
target_world: None,
|
||||||
|
update: AvailableUpdate {
|
||||||
|
installed,
|
||||||
|
current: Some(version("old")),
|
||||||
|
target: version("new"),
|
||||||
|
kind: ContentKind::Mod,
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
let projected = project_updates(&manifest, minecraft, &requests);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
projected.files[0].resolved_project().unwrap().version_id,
|
||||||
|
"new"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
manifest.files[0].resolved_project().unwrap().version_id,
|
||||||
|
"old"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,49 @@ fn concurrent_installs_use_distinct_staging_directories() {
|
|||||||
assert_ne!(staging_directory(minecraft), staging_directory(minecraft));
|
assert_ne!(staging_directory(minecraft), staging_directory(minecraft));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_keeps_replacement_when_a_dependency_is_also_an_update_root() {
|
||||||
|
let selected = version(
|
||||||
|
"library-new",
|
||||||
|
"library",
|
||||||
|
VersionType::Release,
|
||||||
|
"2026-02-01",
|
||||||
|
Vec::new(),
|
||||||
|
);
|
||||||
|
let item = |replacement: bool| PlannedInstall {
|
||||||
|
provider: "modrinth".to_owned(),
|
||||||
|
project_id: "library".to_owned(),
|
||||||
|
title: "Library".to_owned(),
|
||||||
|
version: selected.clone(),
|
||||||
|
installed_path: Some(PathBuf::from("/minecraft/mods/library.jar")),
|
||||||
|
kind: ContentKind::Mod,
|
||||||
|
destination: PathBuf::from("/minecraft/mods"),
|
||||||
|
provider_aliases: Vec::new(),
|
||||||
|
required_dependencies: Vec::new(),
|
||||||
|
automatic_dependency: !replacement,
|
||||||
|
cleanup_eligible: !replacement,
|
||||||
|
replacement,
|
||||||
|
};
|
||||||
|
|
||||||
|
let merged = merge(vec![
|
||||||
|
DependencyPlan {
|
||||||
|
items: vec![item(false)],
|
||||||
|
root_count: 0,
|
||||||
|
optional_dependencies: 0,
|
||||||
|
},
|
||||||
|
DependencyPlan {
|
||||||
|
items: vec![item(true)],
|
||||||
|
root_count: 1,
|
||||||
|
optional_dependencies: 0,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(merged.root_count, 1);
|
||||||
|
assert!(merged.items[0].replacement);
|
||||||
|
assert!(!merged.items[0].automatic_dependency);
|
||||||
|
}
|
||||||
|
|
||||||
struct FakeProvider {
|
struct FakeProvider {
|
||||||
versions: HashMap<String, VersionInfo>,
|
versions: HashMap<String, VersionInfo>,
|
||||||
compatible: HashMap<String, Vec<String>>,
|
compatible: HashMap<String, Vec<String>>,
|
||||||
|
|||||||
Reference in new issue
Block a user