-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
mv: hard link check #4697
mv: hard link check #4697
Conversation
GNU testsuite comparison:
|
nice, could you please add a test ? thanks |
Sure, I'll try to work on that soon. |
src/uu/mv/src/mv.rs
Outdated
let mut is_hard_link = false; | ||
|
||
if target.symlink_metadata().is_ok() { | ||
let source_inode = source.symlink_metadata().unwrap().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.
could you please avoid an unwrap here? Maybe manage the error ?
GNU testsuite comparison:
|
src/uu/mv/src/mv.rs
Outdated
// Hard links are not allowed for directories | ||
if !target_metadata.is_dir() { | ||
let target_inode = target_metadata.ino(); | ||
let source_inode = match source.symlink_metadata() { |
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.
what about something like ?
let source_inode = source.symlink_metadata().map_err(|_| MvError::NoSuchFile(source.quote().to_string()).into())?;
src/uu/mv/src/mv.rs
Outdated
if source_inode.eq(&target_inode) { | ||
is_hard_link = true; | ||
} |
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.
if source_inode.eq(&target_inode) { | |
is_hard_link = true; | |
} | |
is_hard_link = source_inode.ino() == target_inode; |
fails on windows:
|
I'm not really good with windows, should I make the check for hard links run on Unix only or is there a better way to handle this error? |
GNU testsuite comparison:
|
47a54ec
to
f468b24
Compare
GNU testsuite comparison:
|
GNU testsuite comparison:
|
@@ -420,7 +445,7 @@ fn rename( | |||
OverwriteMode::NoClobber => return Ok(()), | |||
OverwriteMode::Interactive => { | |||
if !prompt_yes!("overwrite {}?", to.quote()) { | |||
return Err(io::Error::new(io::ErrorKind::Other, "")); | |||
return Ok(()); |
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.
I think this is the change that makes the CI fail. We have a mechanism to turn a Result
into an exit code. Ok
will be 0
and an error usually 1
. You can get around this with set_exit_code
maybe. Or you could add a new variant Skipped
(or something similar) to the MvError
enum and return that here.
@@ -1,4 +1,3 @@ | |||
// This file is part of the uutils coreutils package. |
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 don't remove this
Closing this PR because the hard link check has been implemented as part of #4831 in the meantime. Thanks anyway for your PR :) |
Related to issue #4613
This pull request checks if files are hard linked.
Current behavior:
Previously this didn't generate an error.
Let me know if there is anything I can change/improve. Thanks!