]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/lib.rs
Auto merge of #78790 - Gankra:rust-src-vendor, r=Mark-Simulacrum
[rust.git] / src / bootstrap / lib.rs
index 3d111839dc7251b86b5f5e4f7d3eabc964ee8883..e7af8b56d563366846e4dec4d160b9078dca750e 100644 (file)
@@ -1171,6 +1171,27 @@ fn read_stamp_file(&self, stamp: &Path) -> Vec<(PathBuf, DependencyType)> {
         paths
     }
 
+    /// Copies a file from `src` to `dst` and doesn't use links, so
+    /// that the copy can be modified without affecting the original.
+    pub fn really_copy(&self, src: &Path, dst: &Path) {
+        if self.config.dry_run {
+            return;
+        }
+        self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst));
+        if src == dst {
+            return;
+        }
+        let _ = fs::remove_file(&dst);
+        let metadata = t!(src.symlink_metadata());
+        if let Err(e) = fs::copy(src, dst) {
+            panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
+        }
+        t!(fs::set_permissions(dst, metadata.permissions()));
+        let atime = FileTime::from_last_access_time(&metadata);
+        let mtime = FileTime::from_last_modification_time(&metadata);
+        t!(filetime::set_file_times(dst, atime, mtime));
+    }
+
     /// Copies a file from `src` to `dst`
     pub fn copy(&self, src: &Path, dst: &Path) {
         if self.config.dry_run {