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 -follow #420

Closed
wants to merge 27 commits into from
Closed

Implement -follow #420

wants to merge 27 commits into from

Conversation

hanbings
Copy link
Collaborator

Closed #308

May conflict with #416, better merge #416 first. :)

There are changes as described in man find:
(The following changes are: When matching files, match the file pointed to by the file link.)

  1. It will use noleaf by default. (But -noleaf has no behavior change yet)
  2. changes the behaviour of the -newer predicate.
  3. consideration applies to -newerXY, -anewer and -cnewer
  4. -type predicate will always match against the type of the file that a symbolic link points to rather than the link itself.
  5. causes the -lname and -ilname predicates always to return false.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.62%. Comparing base (423453e) to head (8443618).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
+ Coverage   66.26%   66.62%   +0.36%     
==========================================
  Files          34       34              
  Lines        4043     4054      +11     
  Branches      916      917       +1     
==========================================
+ Hits         2679     2701      +22     
+ Misses       1000      990      -10     
+ Partials      364      363       -1     

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

Copy link

Commit 93b5ae2 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

Copy link

Commit c1ebc0a 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

@hanbings hanbings marked this pull request as draft July 16, 2024 13:57
Copy link

Commit 5abaed4 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

Copy link

Commit 1b4e25b 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

Copy link

Commit e3911be 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: 192 / SKIP: 1 / FAIL: 95
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

Copy link

Commit 887d76c 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

@hanbings
Copy link
Collaborator Author

hanbings commented Jul 16, 2024

Sorry, the test coverage is still not up to target. :(
They almost always appear in error handling logic and, therefore, are difficult to cover by test code.
I would like to focus on improving coverage after completing all GNU feature implementations.

@hanbings hanbings marked this pull request as ready for review July 16, 2024 16:00
Copy link

Commit 1e1846a 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

Copy link

Commit a0d4e46 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 192 / SKIP: 1 / FAIL: 95

Copy link

Commit eed1c1e 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93

FileAgeRangeMatcher::new(
file_time_type,
minutes,
config.today_start,
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nicer to just pass &config to the matcher constructors so we don't have to keep changing the parameters.

}

impl NewerMatcher {
pub fn new(path_to_file: &str) -> Result<Self, Box<dyn Error>> {
pub fn new(path_to_file: &str, follow: bool) -> Result<Self, Box<dyn Error>> {
let metadata = fs::metadata(path_to_file)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be symlink_metadata() if follow is false. I'd recommend adding a Config::metadata() method or something to centralize the logic.

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, I opened an issue tracking this: #431, and I'd like to open some new PRs to address it. :)

})
}

/// Implementation of matches that returns a result, allowing use to use try!
/// to deal with the errors.
fn matches_impl(&self, file_info: &DirEntry) -> Result<bool, Box<dyn Error>> {
let this_time = file_info.metadata()?.modified()?;
let path = file_info.path();
let this_time = if self.follow && path.is_symlink() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking self.follow here is wrong for command lines like

$ find foo -newer bar -follow

-follow should apply here, but because NewerMatcher::new() was called before -follow was parsed, self.follow will be false. I think the right implementation would pass the final -follow state to matches(), possibly as part of MatcherIO. There could be a convenience method like MatcherIO::metadata(file_info) that handles following symlinks correctly.

(Also, it would be a good idea to cache the Metadata so each matcher doesn't have to do its own stat() call, but that's probably a separate refactoring.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The corresponding logic for using symlink_metadata has been added in the current commit, and I have also opened an issue to track the problem of metadata caching: #430. Thanks!

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

Commit 23675ab 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93

Copy link

Commit 4092697 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: 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

Copy link

Commit 579ae32 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93

Copy link

github-actions bot commented Aug 5, 2024

Commit 2cc61ec 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93

Copy link
Contributor

@tavianator tavianator left a comment

Choose a reason for hiding this comment

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

Presumably you want to call WalkDir::follow_links(config.follow) at some point?

Also, you could implement -L at the same time.

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

github-actions bot commented Aug 6, 2024

Commit a7bf906 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 194 / SKIP: 1 / FAIL: 93

Copy link

Commit aabc8b4 has GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +4 / SKIP +0 / FAIL -4
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 197 / SKIP: 1 / FAIL: 90
Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / 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

Copy link

Commit 8443618 has GNU testsuite comparison:

Run GNU findutils tests: GNU tests summary = TOTAL: 698 / PASS: 449 / FAIL: 246 / 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 +1 / SKIP +0 / FAIL -1
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 197 / SKIP: 1 / FAIL: 90

@tavianator
Copy link
Contributor

@sylvestre #436 contains a squashed version of this PR if you'd rather avoid fixing the tests here

@tavianator
Copy link
Contributor

This can be closed now that #436 was merged

@hanbings hanbings closed this Aug 16, 2024
@hanbings hanbings deleted the implement-308 branch August 16, 2024 15:13
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 -follow
3 participants