bug-fileutils
[Top][All Lists]
Advanced

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

Re: Patch to 'mv' - suppress chmod/chown - New Patch


From: Alain Williams
Subject: Re: Patch to 'mv' - suppress chmod/chown - New Patch
Date: Tue, 25 Mar 2003 10:08:01 +0000
User-agent: Mutt/1.2.5.1i

On Mon, Mar 24, 2003 at 06:55:11PM +0000, Richard Dawe wrote:
> Hello.
> 
> Alain Williams wrote:
> > Please find below a patch to the 'mv' program.
> [snip]
> 
> Which version of fileutils or coreutils is the patch against?
> 
> The current development version is coreutils 4.5.11. coreutils is a combined
> package of fileutils, sh-utils, textutils. You can get the latest version
> here:
> 
>     http://fetish.sf.net/coreutils-4.5.11.tar.gz
> or: http://fetish.sf.net/coreutils-4.5.11.tar.bz2

Please find appended the patch against 4.5.11, there is now also a patch for
coreutils.texi.

Cheers

--- copy.h.orig Sat Jan  4 10:32:54 2003
+++ copy.h      Mon Mar 24 11:31:04 2003
@@ -132,6 +132,14 @@
      if USE_MODE is nonzero.  */
   mode_t mode;
 
+  /* Dont attempt to set permission bits on the destination.
+     Useful when the destination file system does not support this. */
+  int dont_chmod_bits;
+
+  /* Dont attempt to set owner/group on the destination.
+     Useful when the destination file system does not support this. */
+  int dont_owner_and_group;
+
   /* Control creation of sparse files.  */
   enum Sparse_type sparse_mode;
 
--- copy.c.orig Sun Mar  2 06:05:56 2003
+++ copy.c      Mon Mar 24 11:45:50 2003
@@ -1446,7 +1446,7 @@
       /* There's no need to preserve timestamps or permissions.  */
       preserve_metadata = 0;
 
-      if (x->preserve_ownership)
+      if (x->preserve_ownership && ! x->dont_owner_and_group)
        {
          /* Preserve the owner and group of the just-`copied'
             symbolic link, if possible.  */
@@ -1511,7 +1511,8 @@
 
   /* Avoid calling chown if we know it's not necessary.  */
   if (x->preserve_ownership
-      && (new_dst || !SAME_OWNER_AND_GROUP (src_sb, dst_sb)))
+      && (new_dst || !SAME_OWNER_AND_GROUP (src_sb, dst_sb))
+      && !(x->dont_owner_and_group))
     {
       ran_chown = 1;
       if (DO_CHOWN (chown, dst_path, src_sb.st_uid, src_sb.st_gid))
@@ -1542,7 +1543,8 @@
     return delayed_fail;
 
   if ((x->preserve_mode || new_dst)
-      && (x->copy_as_regular || S_ISREG (src_type) || S_ISDIR (src_type)))
+      && (x->copy_as_regular || S_ISREG (src_type) || S_ISDIR (src_type))
+      && !(x->dont_chmod_bits))
     {
       if (chmod (dst_path, get_dest_mode (x, src_mode)))
        {
--- mv.c.orig   Sun Nov 17 09:34:09 2002
+++ mv.c        Mon Mar 24 12:12:14 2003
@@ -84,6 +84,8 @@
   {"backup", optional_argument, NULL, 'b'},
   {"force", no_argument, NULL, 'f'},
   {"interactive", no_argument, NULL, 'i'},
+  {"no-mode", no_argument, NULL, 'M'},
+  {"no-owner", no_argument, NULL, 'O'},
   {"reply", required_argument, NULL, REPLY_OPTION},
   {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
   {"suffix", required_argument, NULL, 'S'},
@@ -135,6 +137,8 @@
   x->symbolic_link = 0;
   x->set_mode = 0;
   x->mode = 0;
+  x->dont_chmod_bits = 0;
+  x->dont_owner_and_group = 0;
   x->stdin_tty = isatty (STDIN_FILENO);
 
   /* Find out the current file creation mask, to knock the right bits
@@ -334,6 +338,8 @@
                                  existing destination file\n\
       --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
                                  argument\n\
+  -M, --no-mode                don't try to preserve mode on copy\n\
+  -O, --no-owner               don't try to preserve user & group on copy\n\
   -S, --suffix=SUFFIX          override the usual backup suffix\n\
 "), stdout);
       fputs (_("\
@@ -393,7 +399,7 @@
 
   errors = 0;
 
-  while ((c = getopt_long (argc, argv, "bfiuvS:V:", long_options, NULL)) != -1)
+  while ((c = getopt_long (argc, argv, "bfiuvS:V:MO", long_options, NULL)) != 
-1)
     {
       switch (c)
        {
@@ -438,6 +444,12 @@
          make_backups = 1;
          backup_suffix_string = optarg;
          break;
+       case 'M':       // don't try to preserve mode on copy
+         x.dont_chmod_bits = 1;
+         break;
+       case 'O':       // don't try to preserve user & group on copy
+         x.dont_owner_and_group = 1;
+         break;
        case_GETOPT_HELP_CHAR;
        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
        default:
--- coreutils.texi.orig Thu Mar 13 13:15:50 2003
+++ coreutils.texi      Tue Mar 25 10:04:36 2003
@@ -6485,6 +6485,11 @@
 own the file, or have write permission on its directory.)  If the
 response does not begin with @samp{y} or @samp{Y}, the file is skipped.
 
+The @code{-M} (@code{--no-mode}) and @code{-O} (@code{--no-owner}) options
+are provided for when the target directory is on a file system that does not
+support explicit file permissions or ownership; where @command{mv} would print
+error messages that are, essentially, meaningless.
+
 @emph{Warning}: If you try to move a symlink that points to a directory,
 and you specify the symlink with a trailing slash, then @command{mv}
 doesn't move the symlink but instead moves the directory referenced
@@ -6555,6 +6560,18 @@
 Append @var{suffix} to each backup file made with @option{-b}.
 @xref{Backup options}.
 
address@hidden -M
address@hidden --no-mode
address@hidden -M
address@hidden --no-mode
+Do not attempt to set the mode on the file once copied.
+
address@hidden -O
address@hidden --no-owner
address@hidden -O
address@hidden --no-owner
+Do not attempt to set the owner/group on the file once copied.
+
 @itemx @address@hidden@var{directory}}
 @opindex --target-directory
 @cindex target directory



-- 
Alain Williams

#include <std_disclaimer.h>




reply via email to

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