From 483ad7c00f2fa74a0a341a5d22546a0df6349dd5 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 20 Jan 2020 00:40:56 +0100 Subject: [PATCH] Keep existing package with git install --- src/cargo/core/workspace.rs | 7 ------- src/cargo/ops/cargo_install.rs | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index dc08811f248..c2cb23a8fa8 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -833,13 +833,6 @@ impl<'cfg> Workspace<'cfg> { pub fn set_target_dir(&mut self, target_dir: Filesystem) { self.target_dir = Some(target_dir); } - - // TODO: This seems like the wrong approach - pub fn set_package(&mut self, package: Package) { - let key = self.current_manifest.parent().unwrap(); - let package = MaybePackage::Package(package); - self.packages.packages.insert(key.to_path_buf(), package); - } } impl<'cfg> Packages<'cfg> { diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 5622c459464..9252256e1e3 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -215,6 +215,7 @@ fn install_one( Some(Filesystem::new(config.cwd().join("target-install"))) }; + let mut git_package = None; let mut ws = match overidden_target_dir { Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?, None => { @@ -222,20 +223,22 @@ fn install_one( ws.set_require_optional_deps(false); // Use tempdir to build git depedencies to prevent bloat in cargo cache - if source_id.is_git() && config.target_dir()?.is_none() { - match TempFileBuilder::new().prefix("cargo-install").tempdir() { - Ok(td) => ws.set_target_dir(Filesystem::new(td.path().to_owned())), - // If tempfile creation fails, write to cargo cache but clean up afterwards - Err(_) => needs_cleanup = true, + if source_id.is_git() { + if config.target_dir()?.is_none() { + match TempFileBuilder::new().prefix("cargo-install").tempdir() { + Ok(td) => ws.set_target_dir(Filesystem::new(td.path().to_owned())), + // If tempfile creation fails, write to cargo cache but clean up afterwards + Err(_) => needs_cleanup = true, + } } + git_package = Some(&pkg); } - ws.set_package(pkg); ws - } + }, }; ws.set_ignore_lock(config.lock_update_allowed()); - let pkg = ws.current()?; + let pkg = git_package.map_or_else(|| ws.current(), |pkg| Ok(pkg))?; if from_cwd { if pkg.manifest().edition() == Edition::Edition2015 {