-
Notifications
You must be signed in to change notification settings - Fork 38
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
find: Implement -samefile
#389
Conversation
Codecov ReportAttention: Patch coverage is
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. |
tests/find_cmd_tests.rs
Outdated
|
||
#[test] | ||
#[serial(working_dir)] | ||
#[cfg(target_os = "linux")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why linux only ? :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
tests/find_cmd_tests.rs
Outdated
|
||
#[test] | ||
#[serial(working_dir)] | ||
#[cfg(target_os = "linux")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(target_os = "linux")] | |
#[cfg(unix)] |
There was a problem hiding this comment.
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
. : )
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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!
And I waiting for #400 to review this first :) |
GNU testsuite comparison:
|
@hanbings is that expected ? :) |
If we mean the GNU/BFS tests for the code in this PR itself, yes. |
GNU testsuite comparison:
|
src/find/matchers/samefile.rs
Outdated
|
||
#[cfg(not(unix))] | ||
fn matches(&self, _file_info: &walkdir::DirEntry, _matcher_io: &mut super::MatcherIO) -> bool { | ||
// FIXME |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, it supports windows? https://github.com/uutils/coreutils/blob/92665144c9ddf100d5044dc0c52af122a94587d0/src/uu/split/src/platform/windows.rs#L47
Oh! That's right! Changed to support multiple platforms. Thanks!
GNU testsuite comparison:
|
GNU testsuite comparison:
|
implement: #373
BFS test
+1 PASS
and GNU testPASS +8
/FAIL -20
in commit bc8ae98