diff --git a/src/main.rs b/src/main.rs index 3b256b4..e712403 100644 --- a/src/main.rs +++ b/src/main.rs @@ -300,8 +300,13 @@ async fn main() -> Result<(), Box> { git, path, } => { + let mut pack_dir: Option = None; let pack_lock = if let Some(git_url) = git { - resolver::PinnedPackMeta::load_from_git_repo(&git_url, true).await? + let (lock_meta, repo_dir) = + resolver::PinnedPackMeta::load_from_git_repo(&git_url, true).await?; + // Hold on to the repo directory until pack_dir is dropped + let _ = pack_dir.insert(repo_dir); + lock_meta } else if let Some(local_path) = path { resolver::PinnedPackMeta::load_from_directory(&local_path, true).await? } else { diff --git a/src/resolver.rs b/src/resolver.rs index 919c1f8..b2f3092 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -382,13 +382,11 @@ impl PinnedPackMeta { Self::load_from_directory(&std::env::current_dir()?, ignore_transitive_versions).await } + /// Load a pack from a git repo cloned to a temporary directory pub async fn load_from_git_repo( git_url: &str, ignore_transitive_versions: bool, - ) -> Result> { - // TODO: Refactor the way this works since temp dirs will be deleted before we get to access local mods - // That is a problem for the future - + ) -> Result<(Self, tempfile::TempDir), Box> { let pack_dir = tempfile::tempdir()?; println!( "Cloning modpack from git repo {} to {:#?}...", @@ -409,6 +407,6 @@ impl PinnedPackMeta { modpack_meta.modloader.to_string() ); - Ok(pinned_pack_meta) + Ok((pinned_pack_meta, pack_dir)) } }