[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cvs admin option to modify file execute bit in repository
From: |
Mark D. Baushke |
Subject: |
Re: cvs admin option to modify file execute bit in repository |
Date: |
Wed, 08 Dec 2004 16:48:36 -0800 |
Here is a revised patch that avoids rewriting the RCS file more than
once and does not make a change unless all of the options make sense.
I also updated to use -Xexec=on and -Xexec=off as the command options.
-- Mark
Index: src/admin.c
===================================================================
RCS file: /cvs/ccvs/src/admin.c,v
retrieving revision 1.101
diff -u -p -r1.101 admin.c
--- src/admin.c 4 Oct 2004 20:37:50 -0000 1.101
+++ src/admin.c 9 Dec 2004 00:42:01 -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-Xexec=off Turn off execute bits on repository file.\n",
+ "\t-Xexec=on 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");
@@ -626,6 +632,7 @@ admin_fileproc (void *callerdat, struct
char *version;
int i;
int status = 0;
+ int execute = -1;
RCSNode *rcs, *rcs2;
vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
@@ -967,6 +974,17 @@ admin_fileproc (void *callerdat, struct
case 'u':
status |= RCS_unlock (rcs, arg[2] ? arg + 2 : NULL, 0);
break;
+ case 'X':
+ if (!strcasecmp (arg + 2, "exec=on"))
+ execute = 1;
+ else if (!strcasecmp (arg + 2, "exec=off"))
+ execute = 0;
+ else
+ {
+ error (0, 0, "%s: `%s' option ignored", rcs->path, arg);
+ status = 1;
+ }
+ break;
default: assert(0); /* can't happen */
}
}
@@ -974,6 +992,46 @@ admin_fileproc (void *callerdat, struct
if (status == 0)
{
RCS_rewrite (rcs, NULL, NULL);
+ /*
+ * Update the execute bit for the file if requested.
+ */
+ if (execute == 0 || execute == 1)
+ {
+ struct stat sb;
+
+ if (CVS_STAT (rcs->path, &sb) < 0)
+ error (0, errno, "cannot stat %s", rcs->path);
+ else
+ {
+ mode_t mode, oumask;
+
+ 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");
+ else
+ {
+ TRACE (TRACE_FLOW, "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);
+ }
+ }
+ }
if (!really_quiet)
cvs_output ("done\n", 5);
}
Index: src/mkmodules.c
===================================================================
RCS file: /cvs/ccvs/src/mkmodules.c,v
retrieving revision 1.88
diff -u -p -r1.88 mkmodules.c
--- src/mkmodules.c 30 Nov 2004 17:12:01 -0000 1.88
+++ src/mkmodules.c 9 Dec 2004 00:42:02 -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",