From e7608372563f99e0b554c48712b516cf3a82df58 Mon Sep 17 00:00:00 2001 From: "Calum H. (IMB11)" Date: Wed, 2 Dec 2026 12:20:35 +0000 Subject: [PATCH 1/2] fix(app): modpack install issue --- packages/app-lib/src/api/pack/install_from.rs | 22 ++- packages/app-lib/src/install/runner.rs | 186 ++++++++---------- 2 files changed, 102 insertions(+), 106 deletions(-) diff --git a/packages/app-lib/src/api/pack/install_from.rs b/packages/app-lib/src/api/pack/install_from.rs index 385a72f70af..cc0aae5ef52 100644 --- a/packages/app-lib/src/api/pack/install_from.rs +++ b/packages/app-lib/src/api/pack/install_from.rs @@ -308,19 +308,27 @@ pub(crate) async fn generate_pack_from_version_id_with_reporter( instance_id: String, reason: DownloadReason, reporter: InstallProgressReporter, -) -> crate::Result { +) -> crate::Result> { let state = State::get().await?; - let version = CachedEntry::get_version( + reporter + .set_context( + InstallErrorContext::new("fetch modpack version") + .project_id(project_id.clone()) + .version_id(version_id.clone()) + .build(), + ) + .await?; + let Some(version) = CachedEntry::get_version( &version_id, Some(CacheBehaviour::Bypass), &state.pool, &state.api_semaphore, ) .await? - .ok_or(ErrorKind::InputError( - "invalid version ID specified".to_string(), - ))?; + else { + return Ok(None); + }; // Update instance with correct loader and game version from the API version metadata, // so the UI shows accurate info while the pack file is still downloading. @@ -473,7 +481,7 @@ pub(crate) async fn generate_pack_from_version_id_with_reporter( .await; } - Ok(CreatePack { + Ok(Some(CreatePack { file: CreatePackFile::Downloaded(file), description: CreatePackDescription { icon, @@ -483,7 +491,7 @@ pub(crate) async fn generate_pack_from_version_id_with_reporter( instance_id, source_filename: None, }, - }) + })) } #[tracing::instrument] diff --git a/packages/app-lib/src/install/runner.rs b/packages/app-lib/src/install/runner.rs index 3b551afbcc6..84597afadb9 100644 --- a/packages/app-lib/src/install/runner.rs +++ b/packages/app-lib/src/install/runner.rs @@ -17,7 +17,7 @@ use super::{diagnostics, recovery, store}; use crate::ErrorKind; use crate::analytics::{self, AppEventType}; use crate::api::pack::install_from::{ - CreatePackLocation, generate_pack_from_file, + CreatePack, CreatePackLocation, generate_pack_from_file, generate_pack_from_version_id_with_reporter, get_instance_from_pack, get_local_pack_instance, }; @@ -1756,27 +1756,15 @@ async fn remove_existing_pack_content( ) .await? .ok_or(ErrorKind::InputError("unknown instance".to_string()))?; - let (project_id, version_id) = match &metadata.link { - InstanceLink::ModrinthModpack { - project_id, - version_id, - } => (project_id.clone(), version_id.clone()), - InstanceLink::ServerProjectModpack { - content_project_id, - content_version_id, - .. - } => (content_project_id.clone(), content_version_id.clone()), + match &metadata.link { + InstanceLink::ModrinthModpack { .. } + | InstanceLink::ServerProjectModpack { .. } => {} InstanceLink::ImportedModpack { .. } => { - remove_existing_imported_pack_content( - instance_id, - &metadata, - state, - ) - .await?; + remove_pack_content_entries(instance_id, &metadata, state).await?; return Ok(HashSet::new()); } _ => return Ok(HashSet::new()), - }; + } let disabled_project_ids = crate::state::instances::commands::list_project_files( @@ -1787,32 +1775,23 @@ async fn remove_existing_pack_content( .into_iter() .filter_map(|file| (!file.enabled).then_some(file.project_id?)) .collect::>(); - let reporter = InstallProgressReporter::new( - job_id, - job_state.clone(), - state.pool.clone(), - ); - let old_pack = generate_pack_from_version_id_with_reporter( - project_id.clone(), - version_id.clone(), - metadata.instance.name.clone(), - None, - instance_id.to_string(), - DownloadReason::Update, - reporter, - ) - .await?; - - crate::api::pack::install_mrpack::remove_all_related_files( - instance_id.to_string(), - old_pack.file, - ) - .await?; + match linked_pack(job_id, job_state, state, &metadata).await? { + Some(old_pack) => { + crate::api::pack::install_mrpack::remove_all_related_files( + instance_id.to_string(), + old_pack.file, + ) + .await?; + } + None => { + remove_pack_content_entries(instance_id, &metadata, state).await?; + } + } Ok(disabled_project_ids) } -async fn remove_existing_imported_pack_content( +async fn remove_pack_content_entries( instance_id: &str, metadata: &crate::state::InstanceMetadata, state: &State, @@ -2015,26 +1994,17 @@ async fn install_pack_inner( version_id, title, icon_url, - } => { - reporter - .set_context( - InstallErrorContext::new("download modpack file") - .project_id(project_id.clone()) - .version_id(version_id.clone()) - .build(), - ) - .await?; - generate_pack_from_version_id_with_reporter( - project_id, - version_id, - title, - icon_url.filter(|_| !preserve_icon && kept_icon.is_none()), - instance_id.clone(), - reason, - reporter.clone(), - ) - .await? - } + } => generate_pack_from_version_id_with_reporter( + project_id, + version_id, + title, + icon_url.filter(|_| !preserve_icon && kept_icon.is_none()), + instance_id.clone(), + reason, + reporter.clone(), + ) + .await? + .ok_or_else(missing_pack_version_error)?, CreatePackLocation::FromFile { path } => { reporter .set_context( @@ -2174,12 +2144,12 @@ async fn update_backup_scope( .. } => { let metadata = instance_metadata(instance_id, state).await?; - let mut packs = vec![(location.clone(), DownloadReason::Modpack)]; - packs.extend( - linked_pack_location(&metadata) - .map(|location| (location, DownloadReason::Update)), - ); - (instance_id, packs) + if let Some(pack) = + linked_pack(job_id, job_state, state, &metadata).await? + { + paths.extend(mrpack_instance_paths(&pack.file).await?); + } + (instance_id, vec![location.clone()]) } InstallRequest::UpdateSharedInstance { instance_id } => { let data = shared_update @@ -2208,12 +2178,7 @@ async fn update_backup_scope( let packs = data .modpack .clone() - .map(|modpack| { - ( - shared_instance_pack_location(modpack), - DownloadReason::Modpack, - ) - }) + .map(shared_instance_pack_location) .into_iter() .collect(); (instance_id, packs) @@ -2221,29 +2186,28 @@ async fn update_backup_scope( _ => return Ok(None), }; paths.extend(SYNCED_OPTION_FILES.map(str::to_string)); - for (location, reason) in packs { + for location in packs { let pack = match location { CreatePackLocation::FromVersionId { project_id, version_id, title, .. - } => { - Box::pin(generate_pack_from_version_id_with_reporter( - project_id, - version_id, - title, - None, - instance_id.clone(), - reason, - InstallProgressReporter::new( - job_id, - job_state.clone(), - state.pool.clone(), - ), - )) - .await? - } + } => Box::pin(generate_pack_from_version_id_with_reporter( + project_id, + version_id, + title, + None, + instance_id.clone(), + DownloadReason::Modpack, + InstallProgressReporter::new( + job_id, + job_state.clone(), + state.pool.clone(), + ), + )) + .await? + .ok_or_else(missing_pack_version_error)?, CreatePackLocation::FromFile { path } => { generate_pack_from_file(path, instance_id.clone()).await? } @@ -2268,10 +2232,13 @@ async fn instance_metadata( }) } -fn linked_pack_location( +async fn linked_pack( + job_id: Uuid, + job_state: &InstallJobState, + state: &State, metadata: &crate::state::InstanceMetadata, -) -> Option { - match &metadata.link { +) -> crate::Result> { + let (project_id, version_id) = match &metadata.link { InstanceLink::ModrinthModpack { project_id, version_id, @@ -2280,14 +2247,35 @@ fn linked_pack_location( content_project_id: project_id, content_version_id: version_id, .. - } => Some(CreatePackLocation::FromVersionId { - project_id: project_id.clone(), - version_id: version_id.clone(), - title: metadata.instance.name.clone(), - icon_url: None, - }), - _ => None, + } => (project_id.clone(), version_id.clone()), + _ => return Ok(None), + }; + let pack = Box::pin(generate_pack_from_version_id_with_reporter( + project_id, + version_id.clone(), + metadata.instance.name.clone(), + None, + metadata.instance.id.clone(), + DownloadReason::Update, + InstallProgressReporter::new( + job_id, + job_state.clone(), + state.pool.clone(), + ), + )) + .await?; + if pack.is_none() { + tracing::warn!( + %job_id, + version_id, + "Linked modpack version no longer exists on Modrinth" + ); } + Ok(pack) +} + +fn missing_pack_version_error() -> crate::Error { + ErrorKind::InputError("invalid version ID specified".to_string()).into() } async fn lock_install_target( From e1df4ce5f42564f9fa26231670329724c28f33c8 Mon Sep 17 00:00:00 2001 From: "Calum H. (IMB11)" Date: Wed, 2 Dec 2026 14:58:57 +0000 Subject: [PATCH 2/2] fix: rev --- .../app-lib/src/api/pack/install_mrpack.rs | 28 ++++++++ packages/app-lib/src/install/runner.rs | 67 ++++++++++++++----- packages/app-lib/src/state/cache.rs | 4 ++ .../state/instances/commands/list_content.rs | 2 + 4 files changed, 84 insertions(+), 17 deletions(-) diff --git a/packages/app-lib/src/api/pack/install_mrpack.rs b/packages/app-lib/src/api/pack/install_mrpack.rs index 777d28ceaf8..9595506d817 100644 --- a/packages/app-lib/src/api/pack/install_mrpack.rs +++ b/packages/app-lib/src/api/pack/install_mrpack.rs @@ -685,6 +685,7 @@ async fn install_zipped_mrpack_files_with_reporter_inner( version_id, file_hashes, project_ids, + mrpack_instance_paths(&file).await?, &state.pool, ) .await?; @@ -1518,6 +1519,33 @@ pub async fn remove_all_related_files( Ok(()) } +pub(crate) async fn remove_recorded_pack_files( + instance_id: &str, + paths: Vec, +) -> crate::Result<()> { + let instance_full_path = + crate::api::instance::get_full_path(instance_id).await?; + for path in paths { + let Ok(path) = SafeRelativeUtf8UnixPathBuf::try_from(path) else { + continue; + }; + if matches!(path.as_str(), "icon.png" | "options.txt") + || crate::state::content_store::is_managed_content_path( + path.as_str(), + ) + { + continue; + } + match io::remove_file(instance_full_path.join(path.as_str())).await { + Ok(_) => (), + Err(err) if err.kind() == ErrorKind::NotFound => (), + Err(err) => return Err(err.into()), + } + } + + Ok(()) +} + #[cfg(test)] mod zip_reader_tests { use super::*; diff --git a/packages/app-lib/src/install/runner.rs b/packages/app-lib/src/install/runner.rs index 84597afadb9..609d7fd0931 100644 --- a/packages/app-lib/src/install/runner.rs +++ b/packages/app-lib/src/install/runner.rs @@ -1785,6 +1785,11 @@ async fn remove_existing_pack_content( } None => { remove_pack_content_entries(instance_id, &metadata, state).await?; + crate::api::pack::install_mrpack::remove_recorded_pack_files( + instance_id, + recorded_pack_paths(&metadata, state).await?, + ) + .await?; } } @@ -2144,10 +2149,13 @@ async fn update_backup_scope( .. } => { let metadata = instance_metadata(instance_id, state).await?; - if let Some(pack) = - linked_pack(job_id, job_state, state, &metadata).await? - { - paths.extend(mrpack_instance_paths(&pack.file).await?); + match linked_pack(job_id, job_state, state, &metadata).await? { + Some(pack) => { + paths.extend(mrpack_instance_paths(&pack.file).await?); + } + None => { + paths.extend(recorded_pack_paths(&metadata, state).await?); + } } (instance_id, vec![location.clone()]) } @@ -2238,21 +2246,12 @@ async fn linked_pack( state: &State, metadata: &crate::state::InstanceMetadata, ) -> crate::Result> { - let (project_id, version_id) = match &metadata.link { - InstanceLink::ModrinthModpack { - project_id, - version_id, - } - | InstanceLink::ServerProjectModpack { - content_project_id: project_id, - content_version_id: version_id, - .. - } => (project_id.clone(), version_id.clone()), - _ => return Ok(None), + let Some((project_id, version_id)) = linked_version(metadata) else { + return Ok(None); }; let pack = Box::pin(generate_pack_from_version_id_with_reporter( - project_id, - version_id.clone(), + project_id.to_string(), + version_id.to_string(), metadata.instance.name.clone(), None, metadata.instance.id.clone(), @@ -2274,6 +2273,40 @@ async fn linked_pack( Ok(pack) } +fn linked_version( + metadata: &crate::state::InstanceMetadata, +) -> Option<(&str, &str)> { + match &metadata.link { + InstanceLink::ModrinthModpack { + project_id, + version_id, + } + | InstanceLink::ServerProjectModpack { + content_project_id: project_id, + content_version_id: version_id, + .. + } => Some((project_id, version_id)), + _ => None, + } +} + +async fn recorded_pack_paths( + metadata: &crate::state::InstanceMetadata, + state: &State, +) -> crate::Result> { + let Some((_, version_id)) = linked_version(metadata) else { + return Ok(Vec::new()); + }; + Ok(crate::state::CachedEntry::get_modpack_files( + version_id, + &state.pool, + &state.api_semaphore, + ) + .await? + .map(|files| files.paths) + .unwrap_or_default()) +} + fn missing_pack_version_error() -> crate::Error { ErrorKind::InputError("invalid version ID specified".to_string()).into() } diff --git a/packages/app-lib/src/state/cache.rs b/packages/app-lib/src/state/cache.rs index 3e3c3ce0fcc..66633c7af98 100644 --- a/packages/app-lib/src/state/cache.rs +++ b/packages/app-lib/src/state/cache.rs @@ -180,6 +180,8 @@ pub struct CachedModpackFiles { pub file_hashes: Vec, #[serde(default)] pub project_ids: Vec, + #[serde(default)] + pub paths: Vec, } /// Cached list of versions for a project (without changelogs for fast loading) @@ -2321,12 +2323,14 @@ impl CachedEntry { version_id: &str, file_hashes: Vec, project_ids: Vec, + paths: Vec, pool: &SqlitePool, ) -> crate::Result<()> { let data = CachedModpackFiles { version_id: version_id.to_string(), file_hashes, project_ids, + paths, }; let entry = CachedEntry { diff --git a/packages/app-lib/src/state/instances/commands/list_content.rs b/packages/app-lib/src/state/instances/commands/list_content.rs index fcd0d938f79..58442626cbf 100644 --- a/packages/app-lib/src/state/instances/commands/list_content.rs +++ b/packages/app-lib/src/state/instances/commands/list_content.rs @@ -1574,6 +1574,7 @@ async fn get_modpack_identifiers( version_id, cached.file_hashes.clone(), project_ids.clone(), + cached.paths, pool, ) .await?; @@ -1720,6 +1721,7 @@ async fn get_modpack_identifiers( version_id, hashes.clone(), project_ids.clone(), + Vec::new(), pool, ) .await?;