]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: give a better diagnostic for nonexistent dest/
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 22 Nov 2010 02:50:41 +0000 (18:50 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 22 Nov 2010 08:04:50 +0000 (00:04 -0800)
This patch was written by Jim Meyering and myself.
* src/copy.c (copy_reg): Turn EISDIR to ENOTDIR to improve the
quality of diagnostics for commands like "cp a nosuch/".  Reported
by Марк Коренберг and Alan Curry in the thread starting at:
http://lists.gnu.org/archive/html/bug-coreutils/2010-11/msg00178.html
* THANKS: Update.
* tests/mv/trailing-slash: Add a test.

THANKS
src/copy.c
tests/mv/trailing-slash

diff --git a/THANKS b/THANKS
index 0123c32662d86bbd31784a52b8d11e1c958dc82b..9bd78c889cf22a8b7e84829365b5784b06e5555e 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -362,6 +362,7 @@ M. P. Suzuki                        mpsuzuki@hiroshima-u.ac.jp
 Maciej Kwapulinski                  pikpok@univ.gda.pl
 Manas Garg                          manas@cygsoft.com
 Manfred Hollstein                   manfred@s-direktnet.de
+Марк Коренберг                      socketpair@gmail.com
 Marc Boucher                        marc@mbsi.ca
 Marc Haber                          mh+debian-bugs@zugschlus.de
 Marc Lehman                         schmorp@schmorp.de
index 07501dfd4c98fd9c79c32f4d7d6945028a070248..42d6d924984e1696346a4ae14d8ac83870499f54 100644 (file)
@@ -603,6 +603,12 @@ copy_reg (char const *src_name, char const *dst_name,
                 }
             }
         }
+
+      /* 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;
     }
   else
     omitted_permissions = 0;
index b58c90822a9f75ed64cbfc78aed9377b3f2bd521..906174afaa41afeab400e91e0cf861fd3d455d96 100755 (executable)
@@ -50,4 +50,12 @@ done
 #touch a a2
 #mv a a2/ && fail=1
 
+# Test for a cp-specific diagnostic introduced after coreutils-8.7:
+printf '%s\n' \
+  "cp: cannot create regular file \`no-such/': Not a directory" \
+> expected-err
+touch b
+cp b no-such/ 2> err && fail=1
+compare err expected-err || fail=1
+
 Exit $fail