cp: correctly copy attributes of a dangling symbolic link#3692
Merged
sylvestre merged 6 commits intouutils:mainfrom Jul 11, 2022
Merged
cp: correctly copy attributes of a dangling symbolic link#3692sylvestre merged 6 commits intouutils:mainfrom
sylvestre merged 6 commits intouutils:mainfrom
Conversation
Add helper method for deciding whether a symbolic link exists in the test directory.
Refactor common code used in several places into a convenience function `is_symlink()` that behaves like `Path::is_symlink()` added in Rust 1.58.0. (We support earlier versions of Rust so we cannot use the standard library version of this function.)
Fix a bug in which `cp` incorrectly exited with an error when attempting to copy the attributes of a dangling symbolic link (that is, when running `cp -P -p`). Fixes uutils#3531.
91cd563 to
4780690
Compare
jfinkels
commented
Jul 4, 2022
| // TODO Replace this convenience function with `Path::is_symlink()` | ||
| // when the minimum supported version of Rust is 1.58 or greater. | ||
| match fs::symlink_metadata(path) { | ||
| Err(_) => false, |
Collaborator
Author
There was a problem hiding this comment.
Because we need to call file_type().is_symlink() on the value stored in Ok(). Could you give an example of what you mean and why it would work better?
Contributor
|
I believe this is a case for a map. fs::symlink_metadata(path)
.map(|m| m.file_type().is_symlink())
.unwrap_or(false) |
Contributor
|
I broke it with a bad rebase, could you please have a look? thanks |
Contributor
|
@sylvestre you should remove the is symlink function from line 987-990 in cp.rs It's already in uucore as of now |
sylvestre
reviewed
Jul 11, 2022
Comment on lines
+1547
to
+1553
| // don't dereference the link | ||
| // | copy permissions, too | ||
| // | | from the link | ||
| // | | | to new file d2 | ||
| // | | | | | ||
| // V V V V | ||
| ucmd.args(&["-P", "-p", "dangle", "d2"]) |
Collaborator
Author
There was a problem hiding this comment.
I was having a hard time remembering the meaning of each argument, so I needed to write it down :)
Collaborator
Author
|
Sorry, I didn't get back to this in time! Thank you for updating it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix a bug in which
cpincorrectly exited with an error whenattempting to copy the attributes of a dangling symbolic link (that
is, when running
cp -P -p).Fixes #3531.
This causes the
tests/cp/preserve-slink-time.shscript in the GNU test suite to change from ERROR to PASS: