Skip to content

find: Implement -samefile - #389

Merged
sylvestre merged 17 commits into
uutils:mainfrom
hanbings:implement-373
Jun 27, 2024
Merged

sylvestre merged 17 commits into
uutils:mainfrom
hanbings:implement-373

Conversation

@hanbings

@hanbings hanbings commented May 24, 2024 •

Copy link
Copy Markdown
Collaborator

implement: #373

BFS test +1 PASS and GNU test PASS +8 / FAIL -20 in commit bc8ae98

@hanbings
hanbings marked this pull request as ready for review May 24, 2024 16:43
@codecov

codecov Bot commented May 24, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 90.69767% with 4 lines in your changes missing coverage. Please review.

Project coverage is 65.43%. Comparing base (42075f5) to head (a523add).
Report is 4 commits behind head on main.

Files Patch % Lines
src/find/matchers/mod.rs 60.00% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #389      +/-   ##
==========================================
+ Coverage   64.96%   65.43%   +0.47%     
==========================================
  Files          32       33       +1     
  Lines        3810     3888      +78     
  Branches      874      892      +18     
==========================================
+ Hits         2475     2544      +69     
  Misses        993      993              
- Partials      342      351       +9     

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

Comment thread tests/find_cmd_tests.rs Outdated

#[test]
#[serial(working_dir)]
#[cfg(target_os = "linux")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why linux only ? :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The -samefile option is primarily used in Linux/Unix systems to determine whether two files are the same file based on their inode (hard link) information.

The ino() method of the MetadataExt can be utilized to obtain the inode.
However, the equivalent file_index() method in std::os::windows::fs::MetadataExt (Rust Docs) on the Windows platform is still considered experimental, so I would recommend exercising caution when using it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So actually I haven't implemented it on Windows platform yet (has left FIXME mark).

@cakebaker cakebaker linked an issue May 25, 2024 that may be closed by this pull request
Comment thread tests/find_cmd_tests.rs Outdated

#[test]
#[serial(working_dir)]
#[cfg(target_os = "linux")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[cfg(target_os = "linux")]
#[cfg(unix)]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. Modified in latest commit. This target is more suitable than linux. : )

Comment thread src/find/matchers/samefile.rs Outdated
#[cfg(unix)]
fn matches(&self, file_info: &walkdir::DirEntry, _matcher_io: &mut super::MatcherIO) -> bool {
let meta = file_info.metadata().unwrap();
meta.ino() == self.metadata.ino()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You also need to check meta.dev(). Otherwise you'll return true for two unrelated files on different filesystems that happen to get the same inode number.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I've added a check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

we have https://github.com/uutils/coreutils/blob/8cac375dddb4d4e87519c137c45fa831ac7f2619/src/uucore/src/lib/features/fs.rs#L559 it would not be a good candidate ?

Thanks! This has now been changed to uucore::fs::paths_refer_to_same_file in f612c0d and it works great!

@sylvestre

Copy link
Copy Markdown
Contributor

And I waiting for #400 to review this first :)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O3 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O2 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 706 / PASS: 441 / FAIL: 262 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +8 / FAIL -20 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +0 / SKIP +0 / FAIL +0
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 182 / SKIP: 1 / FAIL: 105

@sylvestre

Copy link
Copy Markdown
Contributor

@hanbings is that expected ? :)
PASS +8 / FAIL -20 / ERROR +0 / SKIP +0

@hanbings

Copy link
Copy Markdown
Collaborator Author

If we mean the GNU/BFS tests for the code in this PR itself, yes.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +0 / SKIP +0 / FAIL +0
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 182 / SKIP: 1 / FAIL: 105
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O3 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O2 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 706 / PASS: 441 / FAIL: 262 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +8 / FAIL -20 / ERROR +0 / SKIP +0 

Comment thread src/find/matchers/samefile.rs Outdated

#[cfg(not(unix))]
fn matches(&self, _file_info: &walkdir::DirEntry, _matcher_io: &mut super::MatcherIO) -> bool {
// FIXME

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please create an issue for this once it landed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O3 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O2 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 706 / PASS: 441 / FAIL: 262 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +8 / FAIL -20 / ERROR +0 / SKIP +0 
Run BFS tests: Changes from main: PASS +0 / SKIP +0 / FAIL +0
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 184 / SKIP: 1 / FAIL: 103

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Run BFS tests: Changes from main: PASS +0 / SKIP +0 / FAIL +0
Run BFS tests: BFS tests summary = TOTAL: 288 / PASS: 184 / SKIP: 1 / FAIL: 103
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O2 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-copy.new-O3 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O0 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O1 is now passing!
Run GNU findutils tests: Congrats! The GNU test samefile-link.new-O2 is now passing!
Run GNU findutils tests: GNU tests summary = TOTAL: 706 / PASS: 441 / FAIL: 262 / ERROR: 2
Run GNU findutils tests: Changes from main: PASS +8 / FAIL -20 / ERROR +0 / SKIP +0 

@sylvestre
sylvestre merged commit fa4cce8 into uutils:main Jun 27, 2024
@hanbings
hanbings deleted the implement-373 branch July 4, 2024 17:36
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 -samefile

3 participants