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

Implement -fprint #421

Merged
merged 23 commits into from
Aug 11, 2024
Merged

Implement -fprint #421

merged 23 commits into from
Aug 11, 2024

Conversation

hanbings
Copy link
Collaborator

Closed #381

Copy link

codecov bot commented Jul 20, 2024

Codecov Report

Attention: Patch coverage is 86.95652% with 6 lines in your changes missing coverage. Please review.

Project coverage is 66.08%. Comparing base (8b295e7) to head (b38a963).
Report is 3 commits behind head on main.

Files Patch % Lines
src/find/matchers/mod.rs 71.42% 1 Missing and 3 partials ⚠️
src/find/matchers/printer.rs 94.73% 0 Missing and 1 partial ⚠️
tests/find_cmd_tests.rs 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
- Coverage   66.13%   66.08%   -0.06%     
==========================================
  Files          34       34              
  Lines        4004     4042      +38     
  Branches      906      915       +9     
==========================================
+ Hits         2648     2671      +23     
- Misses        997      998       +1     
- Partials      359      373      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Commit e40ae10 has GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +2 / SKIP +0 / FAIL -2
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 193 / SKIP: 1 / FAIL: 94
Run GNU findutils tests: GNU tests summary = TOTAL: 702 / PASS: 445 / FAIL: 254 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +0 / FAIL +0 / ERROR +0 / SKIP +0 
Run GNU findutils tests: Gnu tests No changes

@sylvestre
Copy link
Contributor

needs rebasing please :)

Copy link

Commit 0a6a9e9 has GNU testsuite comparison:

Run GNU findutils tests: GNU tests summary = TOTAL: 702 / PASS: 445 / FAIL: 254 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +0 / FAIL +0 / ERROR +0 / SKIP +0 
Run GNU findutils tests: Gnu tests No changes
Run BFS tests: Changes from main: PASS +2 / SKIP +0 / FAIL -2
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 195 / SKIP: 1 / FAIL: 92

Copy link

Commit 9303508 has GNU testsuite comparison:

Run GNU findutils tests: GNU tests summary = TOTAL: 702 / PASS: 445 / FAIL: 254 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +0 / FAIL +0 / ERROR +0 / SKIP +0 
Run GNU findutils tests: Gnu tests No changes
Run BFS tests: Changes from main: PASS +2 / SKIP +0 / FAIL -2
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 195 / SKIP: 1 / FAIL: 92

if err.kind() == std::io::ErrorKind::NotFound {
File::create(path)?
} else {
return Err(From::from(err));
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think it would be possible to add a test to trigger this case ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked the ErrorKind page, how about we select PermissionDenied as a test case and use the following code to trigger it under Unix system?

#[cfg(unix)]
{
      let result = get_or_create_file("/etc/shadow");
      assert!(result.is_err());
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added it at 823949c I think this is the most stable trigger we can get besides nightly features.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you just use File::create()? That truncates the file, but so does -fprint:

tavianator@tachyon $ echo Hello world >foo
tavianator@tachyon $ find -fprint foo -prune
tavianator@tachyon $ cat foo
.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops... I didn't notice that create includes overwriting existing files. Corrected the code in the new commit. Thanks.

Copy link

Commit 823949c has GNU testsuite comparison:

Run GNU findutils tests: GNU tests summary = TOTAL: 702 / PASS: 445 / FAIL: 254 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +0 / FAIL +0 / ERROR +0 / SKIP +0 
Run GNU findutils tests: Gnu tests No changes
Run BFS tests: Changes from main: PASS +2 / SKIP +0 / FAIL -2
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 195 / SKIP: 1 / FAIL: 92

@hanbings hanbings requested a review from sylvestre July 23, 2024 12:05
Copy link

Commit b255b4e has GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 

Copy link

Commit 3e1b180 has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

Copy link

Commit 2823662 has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

@@ -339,6 +340,19 @@ fn parse_str_to_newer_args(input: &str) -> Option<(String, String)> {
}
}

/// Creates a file if it doesn't exist.
/// If it does exist, it will be overwritten.
fn get_or_create_file(path: &str) -> Result<File, Box<dyn Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

fn get_or_create_file(path: &str) -> Result<File, Box> {
let file = File::create(path)?;
Ok(file)
}
isn't good ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be better to give the user a more friendly prompt here? But yes, it is better to use "?" for now.
I would like to keep get_or_create_file function first, so that it is convenient to modify these unexpected behaviors in a unified way later. :)
Changes have been committed at d02b2c4. thanks.

Copy link

Commit d02b2c4 has GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 

tests/find_cmd_tests.rs Outdated Show resolved Hide resolved
src/find/matchers/printer.rs Outdated Show resolved Hide resolved
file_info.path().to_string_lossy(),
self.delimiter
)
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

GNU find doesn't treat this as a fatal error. You can try -fprint /dev/full on Linux for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, the other comment in the current review have been revised.
and GNU find seems to also interrupt the traversal of the remaining files. Should we also interrupt the traversal and give a suitable message?

Copy link
Contributor

Choose a reason for hiding this comment

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

GNU find doesn't interrupt traversal, but it does delay the error message until the end of traversal. You can see that with something like

tavianator@graphene $ find -print | wc -l
2950167
tavianator@graphene $ find -print -fprint /dev/full | wc -l
find: ‘/dev/full’: No space left on device
2950167

I don't think we need to delay the error message like they do. It's fine to print the error when it happens, but we should continue traversal afterwards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, changed in new commit.

src/find/matchers/printer.rs Outdated Show resolved Hide resolved
Copy link

Commit bc6b06f has GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 

Copy link

github-actions bot commented Aug 5, 2024

Commit 65d23fb has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

Copy link

github-actions bot commented Aug 5, 2024

Commit 267db8a has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

Copy link

github-actions bot commented Aug 5, 2024

Commit da394ad has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

Copy link

github-actions bot commented Aug 5, 2024

Commit b38a963 has GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test print_stdout.new-O3 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +4 / FAIL -8 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +3 / SKIP +0 / FAIL -3
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 196 / SKIP: 1 / FAIL: 91

e
)
.unwrap();
uucore::error::set_exit_code(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a method on MatcherIO, and then you wouldn't need to unset it in the tests

}
i += 1;

let file = get_or_create_file(args[i])?;
Copy link
Contributor

Choose a reason for hiding this comment

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

For future reference: GNU find de-duplicates files, so if you do find -fprint foo -fprint foo it will use the same FILE * for both and you'll get each line twice. Right now uutils will use two different Files and the writes will overlap with each other.

@sylvestre sylvestre merged commit 423453e into uutils:main Aug 11, 2024
19 checks passed
@sylvestre
Copy link
Contributor

@hanbings could you please address the two last comments in new PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement -fprint
3 participants