Subject: Re: bug#22584: cp could be more precise than "Not a directory"

From: Bernhard Voelker <[email-masked]>
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