bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36831: enhance 'directory not empty' message


From: Assaf Gordon
Subject: bug#36831: enhance 'directory not empty' message
Date: Mon, 29 Jul 2019 00:28:07 -0600
User-agent: Mutt/1.11.4 (2019-03-13)

Hello,

On Sun, Jul 28, 2019 at 08:58:59PM +0200, Alex Mantel wrote:
[...] 
> Ah, the target directory does exist! Hmm... But i'd like the message to be
> like:
> 
>    $ mv thing/ ../things
>    mv: cannot move 'thing' to '../things/things': Targetdirectory not empty
> 
>                                                   ^ this little thing here,
>                                                     it explains everyting.
> 
> Change text from 'Directory not empty' to 'Targetdirectory not empty'.

Thanks for the report.

To clarify, the scenario is:

    $ mkdir A B B/A
    $ touch A/bar B/A/foo
    $ mv A B
    mv: cannot move 'A' to 'B/A': Directory not empty

And the reason (as you've found out) is that the target directory 'B/A'
is not empty (has the 'foo' file in it).
Had this been allowed, moving 'A' to 'B/A' would result in the 'foo'
file disappearing.

---

How is a user expecting to know this error is about that target
directory?

There is a bit of a trade-off here between user-friendliness (especially
for non-technical user) and more technical knowledge.
If we go one step 'lower' to the programming interface, almost all
sources mention this is about the 'target' directory not being empty:

POSIX's says:
https://pubs.opengroup.org/onlinepubs/009695399/functions/rename.html
    [EEXIST] or [ENOTEMPTY]
        The link named by new is a directory that is not an empty directory.

Linux's rename(2) manual page says:
    ENOTEMPTY or EEXIST
        newpath is a nonempty directory, that is, contains entries
        other than "." and "..".

FreeBSD's rename(2) manual page says:
    [ENOTEMPTY]        The to argument is a directory and is not empty.

AIX rename(2) manual page says:
     ENOTEMPTY
       The ToPath parameter specifies an existing directory that is
       not empty.


So there is some merit in claiming this helpful piece of information is
lost when the error message is reported to the user.

---

In GNU coreutils this error message originates from 'copy.c' line 2480:
https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/copy.c#n2480

    error (0, rename_errno,
              _("cannot move %s to %s"),
              quoteaf_n (0, src_name), quoteaf_n (1, dst_name));

And herein lies the (technical) problem: The actual message "Directory
not empty" is not in the source code - it is a system error message
that corresponds to the value of 'rename_errno' variable
(ENOTEMPTY/EEXIST). It originates from GLibc (or another libc).

So there is no trivial way to change the error message in coreutils.

Attached a patch to add special handling for this error.

---

What do others think? If this is a desired improvement, I'll finish the
patch with news/tests/etc.


regards,
 - assaf

Attachment: 0001-mv-improve-ENOTEMPTY-EEXIST-error-message.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]