]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: with --parents --no-preserve=mode don't copy dir perms
authorPádraig Brady <P@draigBrady.com>
Thu, 18 Aug 2016 12:54:48 +0000 (13:54 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 18 Aug 2016 12:54:48 +0000 (13:54 +0100)
* src/cp.c (make_dir_parents_private): Use default permissions for
created directories when --no-preserve=mode is specified.
* tests/cp/cp-parents.sh: Add a test case.
* NEWS: Mention the fix.
Fixes http://bugs.gnu.org/24251

NEWS
src/cp.c
tests/cp/cp-parents.sh

diff --git a/NEWS b/NEWS
index c0e0d371a12bebd08611d4020fab4d87c5b1cfe4..34a969e8a5f5871e09a1b2f723c7a44934506916 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   handling ACLs on Cygwin and Solaris platforms. [bug introduced in
   coreutils-8.24]
 
+  cp --parents --no-preserve=mode, no longer copies permissions from source
+  directories, instead using default permissions for created directories.
+  [bug introduced in coreutils-5.93]
+
   chcon, chgrp, chmod, chown, du, and rm, or specifically utilities
   using the FTS interface, now diagnose failures returned by readdir().
   [this bug was inherent in the use of fts: thus, for rm the bug was
index 3b5b6cb72cccce2b4bdbf141b1b0311e776b3913..13dc1ea097c9a31c373fcfe3354dfe29c919bf7f 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -476,7 +476,8 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
                  (src_mode & ~S_IRWXUGO) != 0.  However, common practice is
                  to ask mkdir to copy all the CHMOD_MODE_BITS, letting mkdir
                  decide what to do with S_ISUID | S_ISGID | S_ISVTX.  */
-              mkdir_mode = src_mode & CHMOD_MODE_BITS & ~omitted_permissions;
+              mkdir_mode = x->explicit_no_preserve_mode ? S_IRWXUGO : src_mode;
+              mkdir_mode &= CHMOD_MODE_BITS & ~omitted_permissions;
               if (mkdir (dir, mkdir_mode) != 0)
                 {
                   error (0, errno, _("cannot make directory %s"),
index b0be883dce98eb4e7d8f790288351bc402aab3e6..3819e3d6cb7945e384741ffcf88170504ee71513 100755 (executable)
@@ -1,6 +1,4 @@
 #!/bin/sh
-# cp -R --parents dir-specified-with-trailing-slash/ other-dir
-# would get a failed assertion.
 
 # Copyright (C) 2000-2016 Free Software Foundation, Inc.
 
@@ -25,14 +23,15 @@ working_umask_or_skip_
 # Run the setgid check from the just-created directory.
 skip_if_setgid_
 
-mkdir foo bar || framework_failure_
-mkdir -p a/b/c d e g || framework_failure_
-ln -s d/a sym || framework_failure_
-touch f || framework_failure_
-
+{
+  mkdir foo bar
+  mkdir -p a/b/c d e g
+  ln -s d/a sym
+  touch f
+} || framework_failure_
 
 # With 4.0.37 and earlier (back to when?), this would fail
-# with the failed assertion from dirname.c.
+# with the failed assertion from dirname.c due to the trailing slash.
 cp -R --parents foo/ bar || fail=1
 
 # Exercise the make_path and re_protect code in cp.c.
@@ -55,4 +54,16 @@ p=$(ls -ld g/sym|cut -b-10); case $p in drwx-w--w-);; *) fail=1;; esac
 p=$(ls -ld e/d/a/b/c|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
 p=$(ls -ld g/sym/b/c|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
 
+# Before 8.25 cp --parents --no-preserve=mode would copy
+# the mode bits from the source directories
+{
+  mkdir -p np/b &&
+  chmod 0700 np &&
+  touch np/b/file &&
+  chmod 775 np/b/file &&
+  mkdir np_dest
+} || framework_failure_
+cp --parents --no-preserve=mode np/b/file np_dest/ || fail=1
+p=$(ls -ld np_dest/np|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
+
 Exit $fail