bin/112827: [PATCH]: chmod-like -f & -v options to chflags(1)

Ighighi ighighi at gmail.com
Sat Aug 18 23:00:15 PDT 2007


The following reply was made to PR bin/112827; it has been noted by GNATS.

From: Ighighi <ighighi at gmail.com>
To: bug-followup at freebsd.org
Cc:  
Subject: Re: bin/112827: [PATCH]: chmod-like -f & -v options to chflags(1)
Date: Sun, 19 Aug 2007 01:55:23 -0400

 This is a multi-part message in MIME format.
 --------------050605040509010708060502
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 The patch that must have been attached in the previous post.
 
 --------------050605040509010708060502
 Content-Type: text/x-patch;
  name="chflags.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="chflags.patch"
 
 #
 # (c) 2007 by Ighighi
 #
 # This patch adds support for chmod/chown/chgrp -f & -v options to chflags(1)
 # See http://www.freebsd.org/cgi/query-pr.cgi?pr=112827
 #
 
 --- src/bin/chflags/chflags.c.orig	Sat May 14 19:23:10 2005
 +++ src/bin/chflags/chflags.c	Tue Jun 12 04:41:15 2007
 @@ -62,12 +62,13 @@
  	FTSENT *p;
  	u_long clear, set;
  	long val;
 -	int Hflag, Lflag, Rflag, hflag, ch, fts_options, oct, rval;
 +	int Hflag, Lflag, Rflag, fflag, hflag, vflag, ch, fts_options, oct, rval;
  	char *flags, *ep;
 +	u_long newflags;
  	int (*change_flags)(const char *, unsigned long);
  
 -	Hflag = Lflag = Rflag = hflag = 0;
 -	while ((ch = getopt(argc, argv, "HLPRh")) != -1)
 +	Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
 +	while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
  		switch (ch) {
  		case 'H':
  			Hflag = 1;
 @@ -83,9 +84,15 @@
  		case 'R':
  			Rflag = 1;
  			break;
 +		case 'f':
 +			fflag = 1;
 +			break;
  		case 'h':
  			hflag = 1;
  			break;
 +		case 'v':
 +			vflag++;
 +			break;
  		case '?':
  		default:
  			usage();
 @@ -166,18 +173,20 @@
  		default:
  			break;
  		}
 -		if (oct) {
 -			if (!(*change_flags)(p->fts_accpath, set))
 -				continue;
 -		} else {
 -			p->fts_statp->st_flags |= set;
 -			p->fts_statp->st_flags &= clear;
 -			if (!(*change_flags)(p->fts_accpath,
 -				    (u_long)p->fts_statp->st_flags))
 -				continue;
 +		newflags = oct ? set : (p->fts_statp->st_flags | set) & clear;
 +		if (newflags == p->fts_statp->st_flags)
 +			continue;
 +		if ((*change_flags)(p->fts_accpath, newflags) && !fflag) {
 +			warn("%s", p->fts_path);
 +			rval = 1;
 +		} else if (vflag) {
 +			(void)printf("%s", p->fts_path);
 +
 +			if (vflag > 1)
 +				(void)printf(": 0%lo -> 0%lo",
 +				    (u_long) p->fts_statp->st_flags, newflags);
 +			(void)printf("\n");
  		}
 -		warn("%s", p->fts_path);
 -		rval = 1;
  	}
  	if (errno)
  		err(1, "fts_read");
 @@ -188,6 +197,6 @@
  usage(void)
  {
  	(void)fprintf(stderr,
 -	    "usage: chflags [-h] [-R [-H | -L | -P]] flags file ...\n");
 +	    "usage: chflags [-fhv] [-R [-H | -L | -P]] flags file ...\n");
  	exit(1);
  }
 --- src/bin/chflags/chflags.1.orig	Wed May 17 09:20:21 2006
 +++ src/bin/chflags/chflags.1	Tue Jun 12 04:56:19 2007
 @@ -40,7 +40,7 @@
  .Nd change file flags
  .Sh SYNOPSIS
  .Nm
 -.Op Fl h
 +.Op Fl fhv
  .Oo
  .Fl R
  .Op Fl H | Fl L | Fl P
 @@ -57,6 +57,12 @@
  .Pp
  The options are as follows:
  .Bl -tag -width indent
 +.It Fl f
 +Do not display a diagnostic message if
 +.Nm
 +could not modify the flags for
 +.Va file ,
 +nor modify the exit status to reflect such failures.
  .It Fl H
  If the
  .Fl R
 @@ -79,6 +85,14 @@
  .It Fl R
  Change the file flags for the file hierarchies rooted
  in the files instead of just the files themselves.
 +.It Fl v
 +Cause
 +.Nm
 +to be verbose, showing filenames as the flags are modified.
 +If the
 +.Fl v
 +option is specified more than once, the old and new flags of the file
 +will also be printed, in octal notation.
  .El
  .Pp
  The flags are specified as an octal number or a comma separated list
 
 --------------050605040509010708060502--


More information about the freebsd-bugs mailing list