GNU bug report logs - #9823
request for more correct error reporting of mv

Previous Next

Package: coreutils;

Reported by: francky.leyn <at> telenet.be

Date: Fri, 21 Oct 2011 12:48:02 UTC

Severity: normal

Tags: moreinfo

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9823 in the body.
You can then email your comments to 9823 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Fri, 21 Oct 2011 12:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to francky.leyn <at> telenet.be:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 21 Oct 2011 12:48:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: francky.leyn <at> telenet.be
To: bug-coreutils <at> gnu.org
Cc: Francky Leyn <Francky <at> Leyn.eu>
Subject: request for more correct error reporting of mv
Date: Fri, 21 Oct 2011 14:46:22 +0200 (CEST)
[Message part 1 (text/plain, inline)]

Hello, 



if one uses mv to move a directory, and the target dir already 

exists, mv reports "Directory not empty". 



I find this misleading. The message should also contain the 

message "target dir already exists" or something similar. 



Best regards, 



Francky 
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Fri, 21 Oct 2011 13:01:02 GMT) Full text and rfc822 format available.

Message #8 received at 9823 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: francky.leyn <at> telenet.be
Cc: Francky Leyn <Francky <at> Leyn.eu>, 9823 <at> debbugs.gnu.org
Subject: Re: bug#9823: request for more correct error reporting of mv
Date: Fri, 21 Oct 2011 06:59:22 -0600
tag 9823 moreinfo
thanks

On 10/21/2011 06:46 AM, francky.leyn <at> telenet.be wrote:
>
>
> Hello,
>
>
>
> if one uses mv to move a directory, and the target dir already
>
> exists, mv reports "Directory not empty".

Can you please show a shell session that sets up the necessary paths and 
the actual command you typed that resulted in this message?  A shell 
transcript will make it possible for us to repeat your actions and 
analyze them, much more so than a vague paraphrased English description.

For example, I tried this, and it didn't give an error:

$ rm -rf ?
$ mkdir a b
$ touch b/c
$ mv a b

but it did move a to become b/a.  Meanwhile, I can use a GNU extension 
to reproduce your error message:

$ rm -rf ?
$ mkdir a b
$ touch b/c
$ mv -T a b
mv: cannot move `a' to `b': Directory not empty

But to me, this gives me an expected error - directory b is not empty, 
therefore the syscall rename("a","b") is required to fail by POSIX, and 
POSIX states that the failure will be either EEXIST or ENOTEMPTY (Linux 
chose ENOTEMPTY) - so mv is faithfully reporting the strerror() value of 
the actual error encountered.  It's not possible to change the 
strerror() database, and printing a message not in the strerror() 
database can be confusing to developers that have come to expect 
specific output for specific errno values.

> I find this misleading. The message should also contain the
>
> message "target dir already exists" or something similar.

So it sounds like you'd prefer it if the message were for EEXIST instead 
of ENOTEMPTY?  Have you tried to take it up with the Linux kernel folks? 
 Or maybe coreutils could add a special case that if rename() fails 
with ENOTEMPTY and the conditions are right, then convert the errno to 
EEXIST before calling strerror().  But is it worth the minor 
pessimization (we do have precedence for some errno massaging, but it 
tends to need good justification)?  mv -T is seldom called in the first 
place, since it is not POSIX.

Or did you encounter a scenario with this error message without using 
GNU extensions?

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




Added tag(s) moreinfo. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Fri, 21 Oct 2011 13:01:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Mon, 24 Oct 2011 16:18:02 GMT) Full text and rfc822 format available.

Message #13 received at 9823 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: francky.leyn <at> telenet.be
Cc: Francky Leyn <Francky <at> Leyn.eu>, 9823 <at> debbugs.gnu.org
Subject: Re: bug#9823: request for more correct error reporting of mv
Date: Mon, 24 Oct 2011 10:15:34 -0600
[re-adding the list]

On 10/24/2011 02:06 AM, francky.leyn <at> telenet.be wrote:
> Hello Eric,
>
> This is a sequence which reproduces my situation.
>
>> rm -rf ?
>> mkdir -p a b/a
>> touch b/a/file1 a/file2
>> mv a b
> mv: cannot move `a' to `b/a': Directory not empty

Thanks for your formula.  In fact, you don't even have to touch a/file2; 
simply touching b/a/file1 is enough to reproduce the setup (and even 
makes it more confusing, as then ./a is empty).  The problem is that the 
recursion ends up trying to move the directory ./a (empty or otherwise) 
from the source, and rename(2) it onto the existing directory ./b/a/ on 
the destination; but rename(2) can only succeed if the destination 
directory is empty.
>
> Ok, in this example it's very clear.
> However in my situation it was power play with an account of 120GiB.
> When mv says "Directory not empty" you interpret the error message
> as that of rmdir, and you go looking at dir a, which of course isn't
> empty. It's not immediatly apparent that you have to go looking
> after the dir b/a.
>
> This is the problem I want to address. Would it not be possible
> to add to the error image the following message: "Dir b/a already
> exists" or something similar making the real problem clear right
> from the start?

Like I said earlier, POSIX allows either ENOTEMPTY or EEXIST, and Linux 
happened to choose ENOTEMPTY.  Maybe special-casing that error and 
converting to EEXIST would produce better output.  But someone would 
have to submit a patch.

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




Information forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Mon, 24 Oct 2011 17:53:01 GMT) Full text and rfc822 format available.

Message #16 received at 9823 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: francky.leyn <at> telenet.be
Cc: Francky Leyn <Francky <at> Leyn.eu>, 9823 <at> debbugs.gnu.org
Subject: Re: bug#9823: request for more correct error reporting of mv
Date: Mon, 24 Oct 2011 11:50:26 -0600
[once again, adding the list, so your reply isn't lost]

On 10/24/2011 10:47 AM, francky.leyn <at> telenet.be wrote:
>>> This is the problem I want to address. Would it not be possible
>>> to add to the error image the following message: "Dir b/a already
>>> exists" or something similar making the real problem clear right
>>> from the start?
>>
>> Like I said earlier, POSIX allows either ENOTEMPTY or EEXIST, and
>> Linux
>> happened to choose ENOTEMPTY.  Maybe special-casing that error and
>> converting to EEXIST would produce better output.  But someone would
>> have to submit a patch.
>
> Sorry, I can't submit a patch, it's beyond my capabilities.
> I have submitted the problem, and consider my job done.
>
> Thanks for the reply,
>
> Best regards,
>
> Francky

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




Information forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Tue, 25 Oct 2011 06:41:01 GMT) Full text and rfc822 format available.

Message #19 received at 9823 <at> debbugs.gnu.org (full text, mbox):

From: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
To: Eric Blake <eblake <at> redhat.com>, "francky.leyn <at> telenet.be"
	<francky.leyn <at> telenet.be>
Cc: Francky Leyn <Francky <at> Leyn.eu>,
	"9823 <at> debbugs.gnu.org" <9823 <at> debbugs.gnu.org>
Subject: RE: bug#9823: request for more correct error reporting of mv
Date: Tue, 25 Oct 2011 08:39:07 +0200
Eric Blake wrote:
> On 10/24/2011 02:06 AM, francky.leyn <at> telenet.be wrote:
> > Hello Eric,
> >
> > This is a sequence which reproduces my situation.
> >
> >> rm -rf ?
> >> mkdir -p a b/a
> >> touch b/a/file1 a/file2
> >> mv a b
> > mv: cannot move `a' to `b/a': Directory not empty
> 
> Thanks for your formula.  In fact, you don't even have to touch a/file2; 
> simply touching b/a/file1 is enough to reproduce the setup (and even 
> makes it more confusing, as then ./a is empty).  The problem is that the 
> recursion ends up trying to move the directory ./a (empty or otherwise) 
> from the source, and rename(2) it onto the existing directory ./b/a/ on 
> the destination; but rename(2) can only succeed if the destination 
> directory is empty.
> >
> > Ok, in this example it's very clear.
> > However in my situation it was power play with an account of 120GiB.
> > When mv says "Directory not empty" you interpret the error message
> > as that of rmdir, and you go looking at dir a, which of course isn't
> > empty. It's not immediatly apparent that you have to go looking
> > after the dir b/a.
> >
> > This is the problem I want to address. Would it not be possible
> > to add to the error image the following message: "Dir b/a already
> > exists" or something similar making the real problem clear right
> > from the start?
> 
> Like I said earlier, POSIX allows either ENOTEMPTY or EEXIST, and Linux 
> happened to choose ENOTEMPTY.  Maybe special-casing that error and 
> converting to EEXIST would produce better output.  But someone would 
> have to submit a patch.

I think mv is right to say "Directory not empty". Let's look at
the opposite example, i.e. where the destination _is_ empty:

  rm -rf a b
  mkdir -p a b/a
  strace -e trace=file ../src/mv a b
  ...
  stat("b", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
  lstat("a", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
  lstat("b/a", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
  access("b/a", W_OK)                     = 0
  rename("a", "b/a")                      = 0

The kernel returns success.

Have a nice day,
Berny



Information forwarded to bug-coreutils <at> gnu.org:
bug#9823; Package coreutils. (Tue, 23 Oct 2018 03:17:01 GMT) Full text and rfc822 format available.

Message #22 received at 9823 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: "9823 <at> debbugs.gnu.org" <9823 <at> debbugs.gnu.org>
Subject: Re: bug#9823: request for more correct error reporting of mv
Date: Mon, 22 Oct 2018 21:15:52 -0600
close 9823
stop

(triaging old bugs)

On 25/10/11 12:39 AM, Voelker, Bernhard wrote:
> Eric Blake wrote:
>> Like I said earlier, POSIX allows either ENOTEMPTY or EEXIST, and Linux
>> happened to choose ENOTEMPTY.  Maybe special-casing that error and
>> converting to EEXIST would produce better output.  But someone would
>> have to submit a patch.
> 
> I think mv is right to say "Directory not empty". Let's look at
> the opposite example, i.e. where the destination _is_ empty:

Given the above, and no further comments in 7 years,
I'm closing this bug.

-assaf





bug closed, send any further explanations to 9823 <at> debbugs.gnu.org and francky.leyn <at> telenet.be Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 23 Oct 2018 03:17:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 20 Nov 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 299 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.