Skip to content
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

uucore: add backport for Path::is_symlink() #3697

Merged
merged 3 commits into from
Jul 5, 2022

Conversation

jfinkels
Copy link
Collaborator

@jfinkels jfinkels commented Jul 4, 2022

Add a uucore::fs::is_symlink() function that takes in a
std::path::Path and decides whether the given path is a symbolic
link. 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, and rmdir
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 this

if fs::symlink_metadata(&source)?.file_type().is_symlink() {

where the ? operator propagates an error from symlink_metadata()
to the caller. Now the line of code is

if is_symlink(source) {

in which any error from symlink_metadata() has been converted to
just be a false value. I believe this is a satisfactory tradeoff to
make, 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.)

Add a `uucore::fs::is_symlink()` function that takes in a
`std::path::Path` and decides whether the given path is a symbolic
link. 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`, and `rmdir`
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 this

    if fs::symlink_metadata(&source)?.file_type().is_symlink() {

where the `?` operator propagates an error from `symlink_metadata()`
to the caller. Now the line of code is

    if is_symlink(source) {

in which any error from `symlink_metadata()` has been converted to
just be a `false` value. I believe this is a satisfactory tradeoff to
make, since an error in accessing the file will likely cause an error
later in the same code path.
@sylvestre sylvestre merged commit 666fc29 into uutils:main Jul 5, 2022
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.

None yet

2 participants