[Midnightbsd-cvs] src: bin/chflags: Make chflags(1) more chmod(1) like.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 29 21:16:48 EDT 2008


Log Message:
-----------
Make chflags(1) more chmod(1) like.

Add -v to print file names as they are processed and -vv to print flag names as well.

Add -f to ignore failures.

Obtained from FreeBSD CURRENT.  Submitted to them by Ighighi at gmail.com

Modified Files:
--------------
    src/bin/chflags:
        chflags.1 (r1.3 -> r1.4)
        chflags.c (r1.3 -> r1.4)

-------------- next part --------------
Index: chflags.1
===================================================================
RCS file: /home/cvs/src/bin/chflags/chflags.1,v
retrieving revision 1.3
retrieving revision 1.4
diff -L bin/chflags/chflags.1 -L bin/chflags/chflags.1 -u -r1.3 -r1.4
--- bin/chflags/chflags.1
+++ bin/chflags/chflags.1
@@ -30,10 +30,10 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)chflags.1	8.4 (Berkeley) 5/2/95
-.\" $FreeBSD: /repoman/r/ncvs/src/bin/chflags/chflags.1,v 1.25.2.1 2006/05/17 13:20:21 trhodes Exp $
+.\" $FreeBSD: src/bin/chflags/chflags.1,v 1.25.2.1 2006/05/17 13:20:21 trhodes Exp $
 .\" $MidnightBSD$
 .\"
-.Dd October 6, 2006
+.Dd June 29, 2008
 .Dt CHFLAGS 1
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Nd change file flags
 .Sh SYNOPSIS
 .Nm
-.Op Fl h
+.Op Fl fhv
 .Oo
 .Fl R
 .Op Fl H | Fl L | Fl P
@@ -58,6 +58,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
@@ -80,6 +86,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
Index: chflags.c
===================================================================
RCS file: /home/cvs/src/bin/chflags/chflags.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L bin/chflags/chflags.c -L bin/chflags/chflags.c -u -r1.3 -r1.4
--- bin/chflags/chflags.c
+++ bin/chflags/chflags.c
@@ -62,14 +62,15 @@
 {
 	FTS *ftsp;
 	FTSENT *p;
-	u_long clear, set;
+	u_long clear, newflags, set;
 	long val;
-	int Hflag, Lflag, Rflag, hflag, ch, fts_options, oct, rval;
+	int Hflag, Lflag, Rflag, fflag, hflag, vflag;
+	int ch, fts_options, oct, rval;
 	char *flags, *ep;
 	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;
@@ -85,9 +86,15 @@
 		case 'R':
 			Rflag = 1;
 			break;
+		case 'f':
+			fflag = 1;
+			break;
 		case 'h':
 			hflag = 1;
 			break;
+		case 'v':
+			vflag++;
+			break;
 		case '?':
 		default:
 			usage();
@@ -168,18 +175,23 @@
 		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;
+		if (oct)
+			newflags = set;
+		else
+			newflags = (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");
@@ -190,6 +202,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);
 }


More information about the Midnightbsd-cvs mailing list