Ensure temp modpack repo isn't deleted until we're done downloading mods

This commit is contained in:
Warren Hood 2024-08-20 02:34:22 +02:00
parent 753c9d6417
commit 834d3337db
2 changed files with 9 additions and 6 deletions

View file

@ -300,8 +300,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
git,
path,
} => {
let mut pack_dir: Option<tempfile::TempDir> = 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 {

View file

@ -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<Self, Box<dyn Error>> {
// 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<dyn Error>> {
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))
}
}