Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
drop remove_dst_dir flag and stop using remove_dir_all inside cp_filt…
…ered
  • Loading branch information
klensy committed May 21, 2023
commit 1d4a0bf875532e875becf72478e649e2296a65ab
18 changes: 4 additions & 14 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,28 +1538,21 @@ impl Build {
if self.config.dry_run() {
return;
}
Comment on lines 1538 to 1540
Copy link
Contributor Author

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.

Copy link
Member

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.

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();
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
dont call remove_file in cp_filtered, as self.copy will call copy_internal which will call remove_file itself

Hm, looks like i mean recurse_ function, not cp_filtered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment about remove_dir_all: #111734 (comment)

self.copy(&path, &dst);
Expand Down