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 all commits
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
17 changes: 3 additions & 14 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,18 +1538,7 @@ 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.

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