-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap: (half) merge cp_r and cp_filtered #111734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you say more about removing these lines? What is replacing them / why is it safe to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've described why this line can be removed in commit's title: Hm, looks like i mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment about |
||
self.copy(&path, &dst); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this
dry_run
is only difference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we may break things if we remove it? I'm not sure we want to do this clean up, seems like these functions are distinct if similar today.