mirror of
https://github.com/WarrenHood/MCModpackManager.git
synced 2025-04-30 00:04:59 +01:00
Ensure temp modpack repo isn't deleted until we're done downloading mods
This commit is contained in:
parent
753c9d6417
commit
834d3337db
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue