-
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ered
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1538,28 +1538,21 @@ impl Build { | |
if self.config.dry_run() { | ||
return; | ||
} | ||
self.recurse_(src, dst, Path::new(""), &|_| true, false) | ||
self.recurse_(src, dst, Path::new(""), &|_| true) | ||
} | ||
|
||
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist | ||
/// when this function is called. Unwanted files or directories can be skipped | ||
/// by returning `false` from the filter function. | ||
pub fn cp_filtered(&self, src: &Path, dst: &Path, filter: &dyn Fn(&Path) -> bool) { | ||
// Immediately recurse with an empty relative path | ||
self.recurse_(src, dst, Path::new(""), filter, true) | ||
self.recurse_(src, dst, Path::new(""), filter) | ||
} | ||
|
||
// 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, | ||
remove_dst_dir: bool, | ||
) { | ||
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(); | ||
let name = path.file_name().unwrap(); | ||
|
@@ -1568,11 +1561,8 @@ impl Build { | |
// Only copy file or directory if the filter function returns true | ||
if filter(&relative) { | ||
if t!(f.file_type()).is_dir() { | ||
if remove_dst_dir { | ||
let _ = fs::remove_dir_all(&dst); | ||
} | ||
self.create_dir(&dst); | ||
self.recurse_(&path, &dst, &relative, filter, remove_dst_dir); | ||
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.