uucore: add backport for Path::is_symlink() #3697
Merged
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.
Add a
uucore::fs::is_symlink()
function that takes in astd::path::Path
and decides whether the given path is a symboliclink. This is essentially a backport of the
Path::is_symlink()
function that appears in Rust version 1.58.0. This commit also
replaces some now-duplicate code in
chmod
,cp
,ln
, andrmdir
that checks whether a path is a symbolic link with a call to
is_symlink()
.Technically, this commit slightly changes the behavior of
cp
. Previously, there was a line of code like thiswhere the
?
operator propagates an error fromsymlink_metadata()
to the caller. Now the line of code is
in which any error from
symlink_metadata()
has been converted tojust be a
false
value. I believe this is a satisfactory tradeoff tomake, since an error in accessing the file will likely cause an error
later in the same code path.
(This change was suggested in https://github.com/uutils/coreutils/pull/3692/files#r913039746.)