bug-cvs
[Top][All Lists]
Advanced

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

cvs admin option to modify file execute bit in repository


From: Mark D. Baushke
Subject: cvs admin option to modify file execute bit in repository
Date: Wed, 08 Dec 2004 10:38:04 -0800

Greetings,

This one is kind of old:
  https://ccvs.cvshome.org/issues/show_bug.cgi?id=115

The requestor wants a way to change the execute bits on files so
that when they are subsequently checked out they will default to
the 'correct' value.

The following patch add a -Xchmod+t and -Xchmod-t option to the
'cvs admin' command to alter any files in the repository the user
may desire in this manner.

I am not sure I like the option name.

        Comments?
        -- Mark

Index: admin.c
===================================================================
RCS file: /cvs/ccvs/src/admin.c,v
retrieving revision 1.101
diff -u -p -r1.101 admin.c
--- admin.c     4 Oct 2004 20:37:50 -0000       1.101
+++ admin.c     8 Dec 2004 18:35:36 -0000
@@ -60,6 +60,8 @@ static const char *const admin_usage[] =
     "\t-u[rev]    Unlock the revision (latest revision on branch,\n",
     "\t           latest revision on trunk if omitted).\n",
     "\t-U         Unset strict locking.\n",
+    "\t-Xchmod-t  Turn off execute bits on repository file.\n",
+    "\t-Xchmod+t  Turn on execute bits on respoitory file.\n",
     "(Specify the --help global option for a list of other help options)\n",
     NULL
 };
@@ -230,7 +232,7 @@ admin (int argc, char **argv)
     optind = 0;
     only_allowed_options = true;
     while ((c = getopt (argc, argv,
-                       "+ib::c:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:")) != -1)
+                       "+ib::c:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:X:")) != -1)
     {
        if (
 # ifdef CLIENT_SUPPORT
@@ -417,6 +419,10 @@ admin (int argc, char **argv)
                error (0, 0, "RCS files in CVS always end in ,v");
                goto usage_error;
 
+           case 'X':
+               arg_add (&admin_data, 'X', optarg);
+               break;
+
            case 'V':
                /* No longer supported. */
                error (0, 0, "the `-V' option is obsolete");
@@ -967,6 +973,74 @@ admin_fileproc (void *callerdat, struct 
            case 'u':
                status |= RCS_unlock (rcs, arg[2] ? arg + 2 : NULL, 0);
                break;
+           case 'X':
+               {
+                   int execute = -1;
+                   struct stat sb;
+                   mode_t mode, oumask;
+
+                   if (!strcasecmp (arg + 2, "chmod+x"))
+                       execute = 1;
+                   else if (!strcasecmp (arg + 2, "chmod-x"))
+                       execute = 0;
+                   else
+                   {
+                       error (0, 0, "%s: %s option ignored",
+                              rcs->path, arg);
+                       status = 1;
+                       continue;
+                   }
+
+                   if (CVS_STAT (rcs->path, &sb) < 0)
+                   {
+                       if (!noexec)
+                           error (0, errno, "cannot stat %s", rcs->path);
+                       status = 1;
+                       continue;
+                   }
+                   oumask = umask (0);
+                   (void) umask (oumask);
+
+                   if (execute == 1)
+                   {
+                       mode = sb.st_mode
+                           | (~oumask
+                              & (((sb.st_mode & S_IRUSR) ? S_IXUSR : 0)
+                                 | ((sb.st_mode & S_IRGRP) ? S_IXGRP : 0)
+                                 | ((sb.st_mode & S_IROTH) ? S_IXOTH : 0)));
+                   }
+                   else if (execute == 0)
+                   {
+                       mode = sb.st_mode
+                           & ~(S_IEXEC | S_IXGRP | S_IXOTH) & ~oumask;
+                   }
+
+                   if (mode == sb.st_mode)
+                   {
+                       error (0, 0, "%s: already has %s mode",
+                              rcs->path, execute ? "execute" : "no-execute");
+                       status = 1;
+                       continue;
+                   }
+                   
+                   if (noexec)
+                       continue;
+
+                   /* Need to make sure we own this file. */
+                   if (status == 0 && sb.st_uid != geteuid ())
+                       RCS_rewrite (rcs, NULL, NULL);
+
+                   TRACE ( TRACE_FUNCTION, "chmod(%s,%o)", rcs->path,
+                           (unsigned int) mode );
+
+                   if (chmod (rcs->path, mode) < 0)
+                   {
+                       error (0, errno, "cannot change mode of file %s",
+                              rcs->path);
+                       status = 1;
+                   }
+               }
+               break;
            default: assert(0); /* can't happen */
        }
     }
Index: mkmodules.c
===================================================================
RCS file: /cvs/ccvs/src/mkmodules.c,v
retrieving revision 1.88
diff -u -p -r1.88 mkmodules.c
--- mkmodules.c 30 Nov 2004 17:12:01 -0000      1.88
+++ mkmodules.c 8 Dec 2004 18:35:36 -0000
@@ -529,7 +529,7 @@ static const char *const config_contents
     "#\n",
     "# The following string would enable all `cvs admin' commands for all\n",
     "# users:\n",
-    "#UserAdminOptions=aAbceIklLmnNostuU\n",
+    "#UserAdminOptions=aAbceIklLmnNostuUX\n",
 #ifdef SUPPORT_OLD_INFO_FMT_STRINGS
     "\n",
     "# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system 
by\n",




reply via email to

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