cargo-install: move binaries from the build dir if possible
authorGleb Kozyrev <gleb@gkoz.com>
Sat, 30 Apr 2016 23:46:41 +0000 (02:46 +0300)
committerGleb Kozyrev <gleb@gkoz.com>
Sat, 30 Apr 2016 23:46:41 +0000 (02:46 +0300)
Try moving the binaries (and fall back to copying) if the build
directory is a temporary one (source isn't a local path).

src/cargo/ops/cargo_install.rs

index 237f3aba9570fab8a78f703eefaf08c3c163019c..d3d894e2378b07c57b51d6ba6af7da09ff9d9b33 100644 (file)
@@ -131,6 +131,12 @@ pub fn install(root: Option<&str>,
     let staging_dir = try!(TempDir::new_in(&dst, "cargo-install"));
     for &(bin, src) in binaries.iter() {
         let dst = staging_dir.path().join(bin);
+        // Try to move if `target_dir` is transient.
+        if !source_id.is_path() {
+            if fs::rename(src, &dst).is_ok() {
+                continue
+            }
+        }
         try!(fs::copy(src, &dst).chain_error(|| {
             human(format!("failed to copy `{}` to `{}`", src.display(),
                           dst.display()))