bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "cp --no-preserve=mode" doesn't work as-expected


From: Matt Griswold
Subject: Re: "cp --no-preserve=mode" doesn't work as-expected
Date: Fri, 25 Apr 2008 12:51:16 -0500

* Jim Meyering <address@hidden> [080425 08:55]:
> Patches welcome.

Apologies if I'm over-simplifying, I'm not familiar with the coreutils
code.  This does seem to cause --no-preserve=mode to work as expected
for both directories and files (although it keeps the source's x bit),
and does pass all tests from make check.

Patch against git trunk:

--- a/src/copy.c        2008-04-25 12:21:57.597167502 -0500
+++ b/src/copy.c        2008-04-25 12:35:28.799419214 -0500
@@ -1624,7 +1624,11 @@
      special mode bits may change after the directory is created),
      omit some permissions at first, so unauthorized users cannot nip
      in before the file is ready.  */
-  dst_mode_bits = (x->set_mode ? x->mode : src_mode) & CHMOD_MODE_BITS;
+  dst_mode_bits = (x->set_mode ? x->mode :
+       (x->preserve_mode ? src_mode :
+        src_mode | (S_IRUSR | S_IRGRP | S_IROTH)
+        | (S_IWUSR | S_IWGRP | S_IWOTH)
+       )) & CHMOD_MODE_BITS;
   omitted_permissions =
     (dst_mode_bits
      & (x->preserve_ownership ? S_IRWXG | S_IRWXO
@@ -1827,7 +1831,7 @@
         used as the 3rd argument in the open call.  Historical
         practice passed all the source mode bits to 'open', but the
extra
         bits were ignored, so it should be the same either way.  */
-      if (! copy_reg (src_name, dst_name, x, src_mode & S_IRWXUGO,
+      if (! copy_reg (src_name, dst_name, x, dst_mode_bits & S_IRWXUGO,
                      omitted_permissions, &new_dst, &src_sb))
        goto un_backup;
     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]