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: error message "Directory not empty" is confusing #5102

Open
niron1 opened this issue Jul 20, 2023 · 14 comments
Open

mv: error message "Directory not empty" is confusing #5102

niron1 opened this issue Jul 20, 2023 · 14 comments
Labels

Comments

@niron1
Copy link

niron1 commented Jul 20, 2023

in file coreutils/src/uu/mv/src/mv.rs:488
when you try to move a directory to a location already containing a directory with the same name it would just write "Directory not empty"
first, this is technically a wrong error message because there is no requirement that the destination would be empty.
the destination might as well be populated with some content, we just require that it would not contain a directory with the same name.
also, the error message is confusing because it doesn't state that the problem is with the destination. One can think that the problem is actually with the source, and that the source directory having some kind of attribute that would require it to be empty prior to moving.
I would suggest to change the error message to: "a directory with the same name already exists at destination"

@niron1 niron1 changed the title error message "Directory not empty" in mv, is confusion error message "Directory not empty" in mv, is confusing Jul 20, 2023
@sylvestre
Copy link
Contributor

could you please provide an example how to reproduce this ?

@cakebaker cakebaker changed the title error message "Directory not empty" in mv, is confusing mv: error message "Directory not empty" is confusing Jul 20, 2023
@niron1
Copy link
Author

niron1 commented Jul 20, 2023

sure:

$:rm -rf /tmp/node_modules
$:mkdir -p proj1/node_modules
$:touch proj1/node_modules/foo
$:mkdir -p proj2/node_modules
$:touch proj2/node_modules/bar
$:mv proj1/node_modules /tmp
$:mv proj2/node_modules /tmp
mv: cannot move 'proj2/node_modules' to '/tmp/node_modules': Directory not empty

@sylvestre
Copy link
Contributor

so, if I understand correctly, this issue also happen on the GNU side?
thanks

@niron1
Copy link
Author

niron1 commented Jul 21, 2023

I'm sorry, I'm not that much familiar with the separation of responsibility among linux packages. I know that linux' utils are based on GNU, in general, I was looking for the source code of whomever maintains the 'mv' utility, I looked at the source code (I'm not a Rust developer, but it wasn't too complicated) and the same error messages and apparently the same logic seemed to be related with the file and line I have pointed.

@microcassidy
Copy link

microcassidy commented Jul 21, 2023

The issue is that the directory is non-empty and you are attempting to overwrite data.

mkdir -p foo/bar bar && mv bar foo will execute just fine
mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo will not

@tertsdiepraam
Copy link
Member

I'm not that much familiar with the separation of responsibility among linux packages. I know that linux' utils are based on GNU, in general, I was looking for the source code of whomever maintains the 'mv' utility,

The utils that we maintain here are probably not on your system. That would most likely be the GNU utils. GNU does not operate on GitHub, but they have mailing lists where you can submit suggestions: https://www.gnu.org/software/coreutils/coreutils.html#mailinglists

Our goal is to match the GNU behaviour, so if you get GNU to change this behaviour, we'll follow suit :)

@niron1
Copy link
Author

niron1 commented Jul 21, 2023

I'm not that much familiar with the separation of responsibility among linux packages. I know that linux' utils are based on GNU, in general, I was looking for the source code of whomever maintains the 'mv' utility,

The utils that we maintain here are probably not on your system. That would most likely be the GNU utils. GNU does not operate on GitHub, but they have mailing lists where you can submit suggestions: https://www.gnu.org/software/coreutils/coreutils.html#mailinglists

Our goal is to match the GNU behaviour, so if you get GNU to change this behaviour, we'll follow suit :)

yes, you are right, it's GNU:
mv --help
.
.
GNU coreutils online help: https://www.gnu.org/software/coreutils/
Full documentation https://www.gnu.org/software/coreutils/mv
or available locally via: info '(coreutils) mv invocation'

thanks for your reference. I sent it to gnu. apparently it has to be done via email

@niron1
Copy link
Author

niron1 commented Jul 21, 2023

The issue is that the directory is non-empty and you are attempting to overwrite data.

mkdir -p foo/bar bar && mv bar foo will execute just fine mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo will not

my issue was about improving the phrasing of the error message

@microcassidy
Copy link

The issue is that the directory is non-empty and you are attempting to overwrite data.
mkdir -p foo/bar bar && mv bar foo will execute just fine mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo will not

my issue was about improving the phrasing of the error message

Yeah I understand the confusion but it might just be your understanding of how mv works. There can be a destination directory that shares the same name - It just can't have anything in it, hence their error.
i.e.
mkdir -p foo/bar bar && touch bar/foo && mv bar foo
VS
mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo

@niron1
Copy link
Author

niron1 commented Jul 21, 2023

The issue is that the directory is non-empty and you are attempting to overwrite data.
mkdir -p foo/bar bar && mv bar foo will execute just fine mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo will not

my issue was about improving the phrasing of the error message

Yeah I understand the confusion but it might just be your understanding of how mv works. There can be a destination directory that shares the same name - It just can't have anything in it, hence their error. i.e. mkdir -p foo/bar bar && touch bar/foo && mv bar foo VS mkdir -p foo/bar bar && touch foo/bar/ram && mv bar foo

exactly. your second example would trigger the suboptimal error message

@tertsdiepraam
Copy link
Member

@niron1 do you have a link to the mailing list message? I'd love to follow the discussion there.

@niron1
Copy link
Author

niron1 commented Jul 27, 2023 via email

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Jul 27, 2023

Found it :) https://lists.gnu.org/archive/html/bug-coreutils/2023-07/msg00030.html

I quite like the solution proposed there.

@PThorpe92
Copy link
Contributor

I like that solution. Changing

Cannot move {} into {}: Directory not empty.

into

Cannot overwrite: A non-empty directory: '{}' exists at destination 

Or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants