bug-fileutils
[Top][All Lists]
Advanced

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

Patch to 'mv' - suppress chmod/chown


From: Alain Williams
Subject: Patch to 'mv' - suppress chmod/chown
Date: Mon, 24 Mar 2003 12:38:25 +0000
User-agent: Mutt/1.2.5.1i

Please find below a patch to the 'mv' program.

The purpose is to suppress error messages when copying files to an smb
share (ie a directory mounted from a microsoft box). The options stop
'mv' attempting to 'chown' and 'chmod' the file.

The error was benign in that it worked anyway, but resulted in messages going
on to stderr -- which I don't want to >/dev/null in case there are more 
interesting
errors reported.

I have not provided a patch to the documentation since I could not work out 
which
was the 'master' format. If you let me know which one, I will send in a patch 
for that.

Options added:

-M, --no-mode   don't try to preserve mode on copy
-O, --no-owner  don't try to preserve user & group on copy

--- 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:

-- 
Alain Williams

#include <std_disclaimer.h>




reply via email to

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