GNU bug report logs - #22584
cp could be more precise than "Not a directory"

Previous Next

Package: coreutils;

Reported by: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>

Date: Sun, 7 Feb 2016 16:20:01 UTC

Severity: wishlist

Tags: wontfix

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 22584 in the body.
You can then email your comments to 22584 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#22584; Package coreutils. (Sun, 07 Feb 2016 16:20:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 07 Feb 2016 16:20:01 GMT) Full text and rfc822 format available.

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

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: bug-coreutils <at> gnu.org
Subject: cp could be more precise than "Not a directory"
Date: Mon, 08 Feb 2016 00:19:33 +0800
$ cp .profile /tmp/My_DocVments/
cp: cannot create regular file '/tmp/My_DocVments/': Not a directory

Well can't it be more precise:
No such directory nor file.




Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Sun, 07 Feb 2016 21:54:02 GMT) Full text and rfc822 format available.

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

From: Leslie S Satenstein <lsatenstein <at> yahoo.com>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>, 
 "22584 <at> debbugs.gnu.org" <22584 <at> debbugs.gnu.org>
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Sun, 7 Feb 2016 21:52:55 +0000 (UTC)
[Message part 1 (text/plain, inline)]
Should that be  cp .profile /tmp/My_DocVments   #no trailing slash Regards 
 Leslie
 Mr. Leslie Satenstein
Montréal Québec, Canada



 
      From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
 To: 22584 <at> debbugs.gnu.org 
 Sent: Sunday, February 7, 2016 11:19 AM
 Subject: bug#22584: cp could be more precise than "Not a directory"
   
$ cp .profile /tmp/My_DocVments/cp: cannot create regular file '/tmp/My_DocVments/': Not a directory

Well can't it be more precise:
No such directory nor file.





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

Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Mon, 08 Feb 2016 09:43:01 GMT) Full text and rfc822 format available.

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

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Leslie S Satenstein <lsatenstein <at> yahoo.com>
Cc: "22584 <at> debbugs.gnu.org" <22584 <at> debbugs.gnu.org>
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Mon, 08 Feb 2016 17:41:56 +0800
No I am talking about when there is a slash, but no such file or directory.

>>>>> "LSS" == Leslie S Satenstein <lsatenstein <at> yahoo.com> writes:
LSS> Should that be  cp .profile /tmp/My_DocVments   #no trailing slash




Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Mon, 08 Feb 2016 18:51:01 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>,
 22584 <at> debbugs.gnu.org
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Mon, 8 Feb 2016 09:42:06 -0500
Hello Dan,

A bit more technical information (though not a resolution):

On 02/07/2016 11:19 AM, 積丹尼 Dan Jacobson wrote:
> $ cp .profile /tmp/My_DocVments/
> cp: cannot create regular file '/tmp/My_DocVments/': Not a directory
>
> Well can't it be more precise:
> No such directory nor file.

This is in fact done on purpose, explicitly in the code.

To illustrate:

    $ rm -rf /tmp/foobar
    $ strace -e stat cp .profile /tmp/foobar/
    stat("/tmp/foobar/", 0x7ffe77e60ed0)    = -1 ENOENT (No such file or directory)
    cp: cannot create regular file ‘/tmp/foobar/’: Not a directory

Despite stat(2) return error of 'ENOENT', the code in src/copy.c:1150
sets the error code to ENOTDIR (The comment refers only to 'EISDIR',
perhaps others can expand on why):

        /* Improve quality of diagnostic when a nonexistent dst_name
           ends in a slash and open fails with errno == EISDIR.  */
        if (dest_desc < 0 && dest_errno == EISDIR
               && *dst_name && dst_name[strlen (dst_name) - 1] == '/')
            dest_errno = ENOTDIR;

Then at src/copy.c:1150, the error is reported:

          error (0, dest_errno, _("cannot create regular file %s"),
                 quoteaf (dst_name));

===

Perhaps this is done to simulate the real ENOTDIR which is returned
if the file exist but is not a directory:

    $ rm -rf /tmp/foobar
    $ touch /tmp/foobar
    $ strace -e stat cp ~/.profile /tmp/foobar/
    stat("/tmp/foobar/", 0x7ffd40edf6c0)    = -1 ENOTDIR (Not a directory)
    cp: failed to access ‘/tmp/foobar/’: Not a directory

===


regards,
 - assaf





Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Mon, 08 Feb 2016 21:29:01 GMT) Full text and rfc822 format available.

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

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Assaf Gordon <assafgordon <at> gmail.com>
Cc: 22584 <at> debbugs.gnu.org
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Tue, 09 Feb 2016 05:28:17 +0800
Ah ha, they just should have returned what the system calls said in the
first place, and not tinker with the output!

Them tinkering with the output only makes things worse.




Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Tue, 09 Feb 2016 07:30:02 GMT) Full text and rfc822 format available.

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

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>,
 Assaf Gordon <assafgordon <at> gmail.com>
Cc: 22584 <at> debbugs.gnu.org
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Tue, 9 Feb 2016 08:29:12 +0100
On 02/08/2016 10:28 PM, 積丹尼 Dan Jacobson wrote:
> Ah ha, they just should have returned what the system calls said in the
> first place, and not tinker with the output!
> 
> Them tinkering with the output only makes things worse.

Actually this _is_ an improvement:

After stat() has detected that the target does not exist, cp simply
tries to open() it - and while it has a trailing slash, the kernel
returns EISDIR:

stat("/tmp/My_DocVments/", 0x7ffdd335eee0) = -1 ENOENT (No such file or directory)
...
open("/tmp/My_DocVments/", O_WRONLY|O_CREAT|O_EXCL, 0644) = -1 EISDIR (Is a directory)

Taking this over as-is, the error diagnostic would be quite confusing and
plain wrong:

  cp: cannot create regular file ‘/tmp/My_DocVments/’: Is a directory

Therefore, the current mapping to ENOTDIR - introduced in coreutils-v8.8 -
is the best we can do:

  $ cp .profile /tmp/My_DocVments/
  cp: cannot create regular file ‘/tmp/My_DocVments/’: Not a directory

Your suggestion to say "no such file or directory" (ENOENT) would be misleading,
because the target is treated by the system as a directory due to the trailing
slash.

Have a nice day,
Berny




Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Tue, 09 Feb 2016 18:19:02 GMT) Full text and rfc822 format available.

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

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: 22584 <at> debbugs.gnu.org, Assaf Gordon <assafgordon <at> gmail.com>
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Wed, 10 Feb 2016 02:18:41 +0800
Actually then just returning both
"bla/": No such file or directory
"bla/": Is a directory
would be better.




Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Wed, 10 Feb 2016 01:16:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: 22584 <at> debbugs.gnu.org,
 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Tue, 9 Feb 2016 20:15:35 -0500
> On Feb 9, 2016, at 02:29, Bernhard Voelker <mail <at> bernhard-voelker.de> wrote:
[...]
> 
> After stat() has detected that the target does not exist, cp simply
> tries to open() it - and while it has a trailing slash, the kernel
> returns EISDIR:

Thank you, Bernhard, for pointing the additional open/EISDIR - I missed that part.
That better explains the code in src/copy.c:1150 . 

-assaf





Information forwarded to bug-coreutils <at> gnu.org:
bug#22584; Package coreutils. (Thu, 25 Oct 2018 15:46:01 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: 22584 <at> debbugs.gnu.org
Subject: Re: bug#22584: cp could be more precise than "Not a directory"
Date: Thu, 25 Oct 2018 09:45:11 -0600
severity 22584 wishlist
tags 22584 wontfix
close 22584
stop

(triaging old bugs)

On Tue, Feb 09, 2016 at 08:29:12AM +0100, Bernhard Voelker wrote:
> On 02/08/2016 10:28 PM, 積丹尼 Dan Jacobson wrote:
> > Ah ha, they just should have returned what the system calls said in the
> > first place, and not tinker with the output!
> > 
> > Them tinkering with the output only makes things worse.
> 
> Actually this _is_ an improvement:
> 
> After stat() has detected that the target does not exist, cp simply
> tries to open() it - and while it has a trailing slash, the kernel
> returns EISDIR:
> 
> stat("/tmp/My_DocVments/", 0x7ffdd335eee0) = -1 ENOENT (No such file or directory)
> ...
> open("/tmp/My_DocVments/", O_WRONLY|O_CREAT|O_EXCL, 0644) = -1 EISDIR (Is a directory)
> 
> Taking this over as-is, the error diagnostic would be quite confusing and
> plain wrong:
> 
>   cp: cannot create regular file ‘/tmp/My_DocVments/’: Is a directory
> 
> Therefore, the current mapping to ENOTDIR - introduced in coreutils-v8.8 -
> is the best we can do:
> 
>   $ cp .profile /tmp/My_DocVments/
>   cp: cannot create regular file ‘/tmp/My_DocVments/’: Not a directory
> 
> Your suggestion to say "no such file or directory" (ENOENT) would be misleading,
> because the target is treated by the system as a directory due to the trailing
> slash.
> 

With no further follow-ups to this thread, I'm closing this bug.

-assaf




Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 25 Oct 2018 15:46:02 GMT) Full text and rfc822 format available.

Added tag(s) wontfix. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 25 Oct 2018 15:46:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22584 <at> debbugs.gnu.org and 積丹尼 Dan Jacobson <jidanni <at> jidanni.org> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 25 Oct 2018 15:46: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. (Fri, 23 Nov 2018 12:24:06 GMT) Full text and rfc822 format available.

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

Previous Next


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