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

mv: Fix stderr output mv file into dir and dir into file where both are files #5464

Merged

Conversation

mickvangelderen
Copy link
Contributor

@mickvangelderen mickvangelderen commented Oct 27, 2023

Fixes #5463

The implementation of mv seems a bit messy, at least to a first time reader. My changes also feel a bit "band-aided" in. Glad we have a bunch of tests but the many repeated calls to is_dir and symlink_metadata and hard to understand flow may need to be addressed.

@mickvangelderen mickvangelderen force-pushed the 5463-fix-misleading-error-msg-mv branch 2 times, most recently from 7a3ad9e to cadfb80 Compare October 27, 2023 10:06
Comment on lines 15 to 23
CannotStatNotADirectory(String),
SameFile(String, String),
SelfSubdirectory(String),
SelfTargetSubdirectory(String, String),
DirectoryToNonDirectory(String),
NonDirectoryToDirectory(String, String),
NotADirectory(String),
TargetNotADirectory(String),
FailedToAccessNotADirectory(PathBuf),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use two different errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't they have different outputs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, at least on my machine with Arch Linux GNU mv shows the same error in both cases (see the ticket). I could imagine it depends on the underlying system, so we can leave it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm on Linux pop-os 6.5.6-76060506-generic #202310061235~1697396945~22.04~9283e32 SMP PREEMPT_DYNAMIC Sun O x86_64 x86_64 x86_64 GNU/Linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cakebaker does this PR really achieve the goal of the issue then? Which mv are we trying to emulate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the goal is to get better error messages and your PR achieves it. We try to be compatible with the latest version of mv. In this case it is not possible, though, as the behavior depends on the underlying system. This is why there is no test for it in https://github.com/coreutils/coreutils/blob/master/tests/mv/trailing-slash.sh and the authors write in a comment:

We would like the erroneous-looking "mv any non-dir/" to fail,
but with the current implementation, it depends on how the
underlying rename syscall handles the trailing slash.

/// Returns true if the passed `path` ends with a path terminator.
fn path_ends_with_terminator(path: &Path) -> bool {
path.as_os_str()
.as_bytes()
Copy link
Contributor

@cakebaker cakebaker Oct 27, 2023

Choose a reason for hiding this comment

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

I guess you have seen the error from the CI that there is no as_bytes function under Windows?

Copy link
Contributor Author

@mickvangelderen mickvangelderen Oct 27, 2023

Choose a reason for hiding this comment

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

The pipeline wouldn't run until someone from this project had approved it. Thanks for pointing out that they are running now.

Copy link
Contributor Author

@mickvangelderen mickvangelderen Oct 27, 2023

Choose a reason for hiding this comment

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

@cakebaker can I run the workflows locally? They won't run until they're approved:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

@mickvangelderen the approval is no longer needed and the workflows should run automatically in the future.

@cakebaker cakebaker merged commit 5c100dd into uutils:main Oct 28, 2023
@cakebaker
Copy link
Contributor

Thanks for your PR :)

@mickvangelderen
Copy link
Contributor Author

Thanks for your PR :)

Thanks for the guidance and swift reviews :)

@mickvangelderen mickvangelderen deleted the 5463-fix-misleading-error-msg-mv branch October 28, 2023 13:34
@sylvestre sylvestre changed the title Fix stderr output mv file into dir and dir into file where both are files mv: Fix stderr output mv file into dir and dir into file where both are files Nov 14, 2023
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.

mv: misleading error messages for mv file1 file2/ and mv file1/ file2
2 participants