mirror of
				https://github.com/WarrenHood/MCModpackManager.git
				synced 2025-11-04 01:58:41 +00: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,
 | 
					                git,
 | 
				
			||||||
                path,
 | 
					                path,
 | 
				
			||||||
            } => {
 | 
					            } => {
 | 
				
			||||||
 | 
					                let mut pack_dir: Option<tempfile::TempDir> = None;
 | 
				
			||||||
                let pack_lock = if let Some(git_url) = git {
 | 
					                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 {
 | 
					                } else if let Some(local_path) = path {
 | 
				
			||||||
                    resolver::PinnedPackMeta::load_from_directory(&local_path, true).await?
 | 
					                    resolver::PinnedPackMeta::load_from_directory(&local_path, true).await?
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -382,13 +382,11 @@ impl PinnedPackMeta {
 | 
				
			||||||
        Self::load_from_directory(&std::env::current_dir()?, ignore_transitive_versions).await
 | 
					        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(
 | 
					    pub async fn load_from_git_repo(
 | 
				
			||||||
        git_url: &str,
 | 
					        git_url: &str,
 | 
				
			||||||
        ignore_transitive_versions: bool,
 | 
					        ignore_transitive_versions: bool,
 | 
				
			||||||
    ) -> Result<Self, Box<dyn Error>> {
 | 
					    ) -> Result<(Self, tempfile::TempDir), 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
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let pack_dir = tempfile::tempdir()?;
 | 
					        let pack_dir = tempfile::tempdir()?;
 | 
				
			||||||
        println!(
 | 
					        println!(
 | 
				
			||||||
            "Cloning modpack from git repo {} to {:#?}...",
 | 
					            "Cloning modpack from git repo {} to {:#?}...",
 | 
				
			||||||
| 
						 | 
					@ -409,6 +407,6 @@ impl PinnedPackMeta {
 | 
				
			||||||
            modpack_meta.modloader.to_string()
 | 
					            modpack_meta.modloader.to_string()
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(pinned_pack_meta)
 | 
					        Ok((pinned_pack_meta, pack_dir))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue