diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 3756976dee062..126ef6e31eff0 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1538,18 +1538,7 @@ impl Build { if self.config.dry_run() { return; } - for f in self.read_dir(src) { - let path = f.path(); - let name = path.file_name().unwrap(); - let dst = dst.join(name); - if t!(f.file_type()).is_dir() { - t!(fs::create_dir_all(&dst)); - self.cp_r(&path, &dst); - } else { - let _ = fs::remove_file(&dst); - self.copy(&path, &dst); - } - } + self.recurse_(src, dst, Path::new(""), &|_| true) } /// Copies the `src` directory recursively to `dst`. Both are assumed to exist @@ -1561,6 +1550,8 @@ impl Build { } // Inner function does the actual work + // + // FIXME: consider merging cp_filtered and cp_r into one function fn recurse_(&self, src: &Path, dst: &Path, relative: &Path, filter: &dyn Fn(&Path) -> bool) { for f in self.read_dir(src) { let path = f.path(); @@ -1570,11 +1561,9 @@ impl Build { // Only copy file or directory if the filter function returns true if filter(&relative) { if t!(f.file_type()).is_dir() { - let _ = fs::remove_dir_all(&dst); self.create_dir(&dst); self.recurse_(&path, &dst, &relative, filter); } else { - let _ = fs::remove_file(&dst); self.copy(&path, &dst); } }