From c3479fbc1a7ab135d71daa55aabf7f4834af7971 Mon Sep 17 00:00:00 2001 From: Konstantin Welke Date: Sun, 20 Sep 2015 09:35:47 +0200 Subject: [PATCH 1/3] If hard-linking fails, try to copy (in assemble()) --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 61f768a..94ec9cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -468,7 +468,10 @@ impl Config { // exist for now. let lib_dst = dst.with_file_name(format!("{}.lib", lib_name)); let _ = fs::remove_file(&lib_dst); - fs::hard_link(dst, lib_dst).unwrap(); + if fs::hard_link(&dst, &lib_dst).is_err() { + println!("Hard-linking from {:?} to {:?} failed. Trying to copy...", dst, lib_dst); + fs::copy(&dst, &lib_dst).expect("Copying from {:?} to {:?} FAILED."); + }; } else { let ar = self.get_ar(); let cmd = ar.file_name().unwrap().to_string_lossy(); From 9837db24dbd8f4614ffbf50ad5db2913c340f0b1 Mon Sep 17 00:00:00 2001 From: Konstantin Welke Date: Mon, 21 Sep 2015 17:48:27 +0200 Subject: [PATCH 2/3] don't println! on hard-link failure --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94ec9cd..0d8dd4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -468,10 +468,10 @@ impl Config { // exist for now. let lib_dst = dst.with_file_name(format!("{}.lib", lib_name)); let _ = fs::remove_file(&lib_dst); - if fs::hard_link(&dst, &lib_dst).is_err() { - println!("Hard-linking from {:?} to {:?} failed. Trying to copy...", dst, lib_dst); - fs::copy(&dst, &lib_dst).expect("Copying from {:?} to {:?} FAILED."); - }; + fs::hard_link(&dst, &lib_dst).or_else(|_| { + //if hard-link fails, just copy (ignoring the number of bytes written) + fs::copy(&dst, &lib_dst).map(|_| ()) + }).expect("Copying from {:?} to {:?} failed.");; } else { let ar = self.get_ar(); let cmd = ar.file_name().unwrap().to_string_lossy(); From 700e4b827b548172ce7598948858401c79e594db Mon Sep 17 00:00:00 2001 From: Konstantin Welke Date: Mon, 21 Sep 2015 20:06:05 +0200 Subject: [PATCH 3/3] .ok.expect() so it compiles in older versions --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0d8dd4f..25d368c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -471,7 +471,7 @@ impl Config { fs::hard_link(&dst, &lib_dst).or_else(|_| { //if hard-link fails, just copy (ignoring the number of bytes written) fs::copy(&dst, &lib_dst).map(|_| ()) - }).expect("Copying from {:?} to {:?} failed.");; + }).ok().expect("Copying from {:?} to {:?} failed.");; } else { let ar = self.get_ar(); let cmd = ar.file_name().unwrap().to_string_lossy();