]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: improve status message when omitting directories
authorPádraig Brady <P@draigBrady.com>
Sat, 19 Nov 2016 11:26:43 +0000 (11:26 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 19 Nov 2016 17:05:33 +0000 (17:05 +0000)
* src/copy.h (cp_options): Add a new flag for install(1).
* src/copy.c (copy_internal): For cp, also output remediation
advice which also indicates why directories aren't copied by default.
The message is unchanged for install(1).
* src/cp.c (cp_option_init): Init install_mode to false.
* src/mv.c (cp_option_init): Likewise.
* src/install.c (cp_option_init): Init install_mode to true.
* tests/install/basic-1.sh: Add a test case.
* tests/cp/link-deref.sh: Adjust test case.
Fixes http://bugs.gnu.org/24958

src/copy.c
src/copy.h
src/cp.c
src/install.c
src/mv.c
tests/cp/link-deref.sh
tests/install/basic-1.sh

index 422d50efed24163ab04a54af801e1838db412f16..b3acff347b52692857d7be5ef5c9f683cd3d32cd 100644 (file)
@@ -1873,7 +1873,10 @@ copy_internal (char const *src_name, char const *dst_name,
 
   if (S_ISDIR (src_mode) && !x->recursive)
     {
-      error (0, 0, _("omitting directory %s"), quoteaf (src_name));
+      error (0, 0, ! x->install_mode /* cp */
+                   ? _("-r not specified; omitting directory %s")
+                   : _("omitting directory %s"),
+             quoteaf (src_name));
       return false;
     }
 
index fa0c2aeae69103303bc4c0e81dd2a58bacdb6d68..a516002c2520fc8bad4485ae7d709c506d984a70 100644 (file)
@@ -137,6 +137,9 @@ struct cp_options
      If that fails, then resort to copying.  */
   bool move_mode;
 
+  /* If true, install(1) is the caller.  */
+  bool install_mode;
+
   /* Whether this process has appropriate privileges to chown a file
      whose owner is not the effective user ID.  */
   bool chown_privileges;
index 926e05be34f79da6659743aeaa87e27148b9c7f4..1b528c6a21818cf83055baba53e99a11166b0413 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -771,6 +771,7 @@ cp_option_init (struct cp_options *x)
   x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
   x->move_mode = false;
+  x->install_mode = false;
   x->one_file_system = false;
   x->reflink_mode = REFLINK_NEVER;
 
index 4fa4bb3d363935a642356e5c41e14b1995d3aa06..414d645cc9a03897cc3f247318ef30c0840a4ba4 100644 (file)
@@ -271,6 +271,7 @@ cp_option_init (struct cp_options *x)
   x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
   x->move_mode = false;
+  x->install_mode = true;
   x->one_file_system = false;
   x->preserve_ownership = false;
   x->preserve_links = false;
index 6a3d0d277cbbf2f58d5c95f32a0e6558688d1069..04d2be3ecc551df8a73d0413cceb55b235a4838b 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -114,6 +114,7 @@ cp_option_init (struct cp_options *x)
   x->hard_link = false;
   x->interactive = I_UNSPECIFIED;
   x->move_mode = true;
+  x->install_mode = false;
   x->one_file_system = false;
   x->preserve_ownership = true;
   x->preserve_links = true;
index 51b228cbbf620054fa2b875e3d81b89c44623095..f5b7160a6088004480317fd15ea8e233d8faf988 100755 (executable)
@@ -92,7 +92,7 @@ for src in dirlink filelink danglink; do
         exp_result=1
         exp_inode=
         exp_ftype=
-        exp_error="cp: omitting directory 'dirlink'"
+        exp_error="cp: -r not specified; omitting directory 'dirlink'"
       elif [ "$src" = 'dirlink' ]; then
         # cp --link -R 'dirlink' should create a new directory.
         exp_result=0
index 23a2d581fda59a02f7c84c15ec51c1ec489c9f4b..1a7147c1f7945023615317318b351da51c96b64a 100755 (executable)
@@ -143,4 +143,9 @@ compare - out <<\EOF || fail=1
 'file' -> 'sub4/dir_exists/file'
 EOF
 
+# Ensure omitted directories are diagnosed
+returns_ 1 ginstall . . 2>err || fail=1
+printf '%s\n' "ginstall: omitting directory '.'" >exp || framework_failure_
+compare exp err || fail=1
+
 Exit $fail