Skip to content

Conversation

@dshemetov
Copy link
Contributor

@dshemetov dshemetov commented Dec 20, 2025

Took a stab at fixing #9703.

Trapping the dangling symlink error seems straightforward via ErrorKind::NotFound, but I'm not familiar enough with the other errors that could happen here to know whether falling back to fs::symlink_metadata(path) is appropriate. Seems safe to fix one error at a time I suppose.

dangling_symlink.to_str().unwrap(),
"some_file",
])
.fails();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the

.stderr_contains

To validate what the error message is?

}
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test will run on many platforms and looking at std::os::unix::fs::symlink this will probably fail on non unix systems, ideally if you can find a way to also run this on windows or otherwise just gate it with a cfg[] for unix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right thanks, I'll look around for something cross-platform here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok copied the approach in symlink_file in cp.rs, hopefully that's good enough

@ChrisDryden
Copy link
Collaborator

Just some minor comments about validating that the test gives the right error message, but it looks like the implementation is correct and I'm able to replicate the fix is working after building locally with

cd /tmp && rm -rf touch-test && mkdir touch-test && cd touch-test && ln -s /nope ref && target/release/touch -r ref out 2>&1; echo "exit: $?"
touch: failed to get attributes of 'ref': No such file or directory
exit: 1

@dshemetov
Copy link
Contributor Author

dshemetov commented Dec 20, 2025

Thanks for the review!

Does uutils try to imitate error messages from GNU? This particular error message seems ambiguous to me. I could take a stab at updating the touch-error-reference-file-inaccessible message (though probably only the en locale).

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/tail/inotify-dir-recreate is now passing!

@sylvestre
Copy link
Contributor

Thanks for the review!

Does uutils try to imitate error messages from GNU? GNU's error message reads more clearly in this case to me "reference is inaccessible". What do yall think? I could take a stab at updating the touch-error-reference-file-inaccessible message (though probably only the en locale).

by default, we do like GNU, but if we can provide a better message, we don't hesitate to do it :)

@dshemetov
Copy link
Contributor Author

dshemetov commented Dec 20, 2025

by default, we do like GNU, but if we can provide a better message, we don't hesitate to do it :)

Sounds reasonable!

Ok, just want to double check how others feel about an error message update

# Current 
touch: failed to get attributes of 'ref': No such file or directory
# Proposed
touch: the target of the symlink 'ref' does not exist

Happy to go with another wording, just feel inclined to resolve the ambiguity in "No such file or directory" (the symlink is missing or the referent?). If yall are happy with this wording, I'm happy to have that change ride along in this PR, otherwise we can merge this (seemingly complete?) fix PR and do the message update in another.

@sylvestre
Copy link
Contributor

Sounds good

@dshemetov
Copy link
Contributor Author

@sylvestre Would you mind translating this to French so I can update the fr locale as well? :)

the target of the symlink { $path } does not exist

@sylvestre sylvestre merged commit 949f038 into uutils:main Dec 23, 2025
127 checks passed
@sylvestre
Copy link
Contributor

@dshemetov "la cible du lien symbolique {path} n'existe pas"
it can be done in a new pr :)

@dshemetov dshemetov deleted the ds/touch-dangling-symlink branch December 24, 2025 00:42
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.

3 participants