Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 May 2002 06:01:34 +0000
From:      Dima Dorfman <dima@trit.org>
To:        Giorgos Keramidas <keramida@FreeBSD.ORG>
Cc:        current@FreeBSD.ORG
Subject:   Re: mergemaster(8) broken -- uses Perl 
Message-ID:  <20020519060134.AF15F3E1A@turbine.trit.org>
In-Reply-To: <20020519022922.GA10039@hades.hell.gr>; from keramida@FreeBSD.ORG on "Sun, 19 May 2002 05:29:22 %2B0300"

next in thread | previous in thread | raw e-mail | index | archive | help
Giorgos Keramidas <keramida@FreeBSD.ORG> wrote:
> On 2002-05-18 11:54, David O'Brien wrote:
> > Anyone got a patch?
> 
> Part of the problems I had when I tried to replace perl in
> mergemaster.sh with something `native' was that the perl code uses
> stat(2) to obtain the permission bits of a directory/file and I can't
> think of a way to do this with tools in the base system without
> resorting to ugly awk scripts that parse and translate ls(1) output.

How about fixing ls(1) to output the numeric mode if asked to?  E.g.,
instead of
	
> 	% /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\
> 	awk -v mode=0 '{
>[...]

	/bin/ls -ldN /tmp | awk '{ print $1 }'

A proof-of-concept (i.e., not polished or fully-tested (in particular,
it lacks a manual page update)) patch to implement ls -N is attached
below.  I've wanted this feature a number of times in the past, but
never had occasion to actually implement it until now.  Note also that
if this is used in mergemaster, we need to deal with the issue of what
to do if mergemaster is run on a system that doesn't have this option
yet (perhaps try it first, and fall back to Perl (which should exist
on systems without ls -N) if it doesn't work?).

Index: ls.c
===================================================================
RCS file: /ref/cvsf/src/bin/ls/ls.c,v
retrieving revision 1.56
diff -u -r1.56 ls.c
--- ls.c	19 Feb 2002 00:05:50 -0000	1.56
+++ ls.c	19 May 2002 05:49:53 -0000
@@ -106,6 +106,7 @@
 static int f_nosort;		/* don't sort output */
        int f_notabs;		/* don't use tab-separated multi-col output */
 static int f_numericonly;	/* don't convert uid/gid to name */
+       int f_numeric_mode;	/* don't convert file modes to a string */
        int f_octal;		/* show unprintables as \xxx */
        int f_octal_escape;	/* like f_octal but use C escapes if possible */
 static int f_recursive;		/* ls subdirectories also */
@@ -167,7 +168,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
- 	while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklnoqrstuw")) != -1) {
+ 	while ((ch = getopt(argc, argv, "1ABCFGHLNPRTWZabcdfghiklnoqrstuw")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C and -l options all override each other so shell
@@ -246,6 +247,9 @@
 			break;
 		case 'n':
 			f_numericonly = 1;
+			break;
+		case 'N':
+			f_numeric_mode = 1;
 			break;
 		case 'o':
 			f_flags = 1;
Index: ls.h
===================================================================
RCS file: /ref/cvsf/src/bin/ls/ls.h,v
retrieving revision 1.17
diff -u -r1.17 ls.h
--- ls.h	3 Feb 2002 19:11:32 -0000	1.17
+++ ls.h	19 May 2002 05:49:07 -0000
@@ -48,6 +48,7 @@
 extern int f_lomac;		/* show LOMAC attributes */
 extern int f_inode;		/* print inode */
 extern int f_longform;		/* long listing format */
+extern int f_numeric_mode;	/* don't convert file modes to a string */
 extern int f_octal;		/* print unprintables in octal */
 extern int f_octal_escape;	/* like f_octal but use C escapes if possible */
 extern int f_nonprint;		/* show unprintables as ? */
Index: print.c
===================================================================
RCS file: /ref/cvsf/src/bin/ls/print.c,v
retrieving revision 1.53
diff -u -r1.53 print.c
--- print.c	25 Feb 2002 01:36:59 -0000	1.53
+++ print.c	19 May 2002 05:49:30 -0000
@@ -177,7 +177,10 @@
 		if (f_size)
 			(void)printf("%*lld ",
 			    dp->s_block, howmany(sp->st_blocks, blocksize));
-		strmode(sp->st_mode, buf);
+		if (f_numeric_mode)
+			snprintf(buf, sizeof(buf), "%.6o", sp->st_mode);
+		else
+			strmode(sp->st_mode, buf);
 		np = p->fts_pointer;
 		(void)printf("%s %*u %-*s  %-*s  ", buf, dp->s_nlink,
 		    sp->st_nlink, dp->s_user, np->user, dp->s_group,
Index: util.c
===================================================================
RCS file: /ref/cvsf/src/bin/ls/util.c,v
retrieving revision 1.29
diff -u -r1.29 util.c
--- util.c	28 Feb 2002 18:52:47 -0000	1.29
+++ util.c	19 May 2002 05:50:08 -0000
@@ -158,9 +158,9 @@
 {
 	(void)fprintf(stderr,
 #ifdef COLORLS
-	"usage: ls [-ABCFGHLPRTWZabcdfghiklnoqrstu1]"
+	"usage: ls [-ABCFGHLNPRTWZabcdfghiklnoqrstu1]"
 #else
-	"usage: ls [-ABCFHLPRTWZabcdfghiklnoqrstu1]"
+	"usage: ls [-ABCFHLNPRTWZabcdfghiklnoqrstu1]"
 #endif
 		      " [file ...]\n");
 	exit(1);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020519060134.AF15F3E1A>