[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
New feature for chmod (and I'm surprised nobody got around to it...)
From: |
Brendan Byrd |
Subject: |
New feature for chmod (and I'm surprised nobody got around to it...) |
Date: |
Thu, 02 Aug 2001 11:13:31 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010628 |
-d, --filesonly don't change the permissions of directories
Ever ran a "chmod -x *" command, but hate having to go back and re-chmod
the directories? Now you don't have to with a "chmod -d -X *" command.
This program has been out for how long? I'm really surprised it's not
in here by now. There have been a number of occasions when I wanted
something like this, so I finally broke down and hacked it in. Enjoy!
--
Brendan Byrd (address@hidden)
System Administrator @ Mission Data
http://www.missiondata.com/
*** chmod.c Sun Nov 19 11:56:33 2000
--- chmod-new.c Thu Aug 2 11:07:11 2001
***************
*** 15,21 ****
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
! /* Written by David MacKenzie <address@hidden> */
#include <config.h>
#include <stdio.h>
--- 15,22 ----
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
! /* Written by David MacKenzie <address@hidden>
! -d option by Brendan Byrd <address@hidden> */
#include <config.h>
#include <stdio.h>
***************
*** 65,70 ****
--- 66,74 ----
/* If nonzero, change the modes of directories recursively. */
static int recurse;
+ /* If nonzero, don't change the permissions of directories. */
+ static int files_only;
+
/* If nonzero, force silence (no error messages). */
static int force_silent;
***************
*** 85,90 ****
--- 89,95 ----
static struct option const long_options[] =
{
{"recursive", no_argument, 0, 'R'},
+ {"filesonly", no_argument, 0, 'd'},
{"changes", no_argument, 0, 'c'},
{"silent", no_argument, 0, 'f'},
{"quiet", no_argument, 0, 'f'},
***************
*** 186,207 ****
}
#endif
! newmode = mode_adjust (file_stats.st_mode, changes);
!
! fail = chmod (file, newmode);
! saved_errno = errno;
!
! if (verbosity == V_high
! || (verbosity == V_changes_only
! && !fail && mode_changed (file, file_stats.st_mode)))
! describe_change (file, newmode, (fail ? CH_FAILED : CH_SUCCEEDED));
!
! if (fail)
! {
! if (force_silent == 0)
! error (0, saved_errno, _("changing permissions of %s"),
! quote (file));
! errors = 1;
}
if (recurse && S_ISDIR (file_stats.st_mode))
--- 191,215 ----
}
#endif
! if (!(files_only && S_ISDIR (file_stats.st_mode)))
! {
! newmode = mode_adjust (file_stats.st_mode, changes);
!
! fail = chmod (file, newmode);
! saved_errno = errno;
!
! if (verbosity == V_high
! || (verbosity == V_changes_only
! && !fail && mode_changed (file, file_stats.st_mode)))
! describe_change (file, newmode, (fail ? CH_FAILED : CH_SUCCEEDED));
!
! if (fail)
! {
! if (force_silent == 0)
! error (0, saved_errno, _("changing permissions of %s"),
! quote (file));
! errors = 1;
! }
}
if (recurse && S_ISDIR (file_stats.st_mode))
***************
*** 278,283 ****
--- 286,292 ----
-v, --verbose output a diagnostic for every file processed\n\
--reference=RFILE use RFILE's mode instead of MODE values\n\
-R, --recursive change files and directories recursively\n\
+ -d, --filesonly don't change the permissions of directories\n\
--help display this help and exit\n\
--version output version information and exit\n\
\n\
***************
*** 314,320 ****
{
thisind = optind ? optind : 1;
! c = getopt_long (argc, argv, "RcfvrwxXstugoa,+-=", long_options, NULL);
if (c == -1)
break;
--- 323,329 ----
{
thisind = optind ? optind : 1;
! c = getopt_long (argc, argv, "RcdfvrwxXstugoa,+-=", long_options, NULL);
if (c == -1)
break;
***************
*** 354,359 ****
--- 363,371 ----
case 'c':
verbosity = V_changes_only;
break;
+ case 'd':
+ files_only = 1;
+ break;
case 'f':
force_silent = 1;
break;
- New feature for chmod (and I'm surprised nobody got around to it...),
Brendan Byrd <=