Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 May 2002 05:29:22 +0300
From:      Giorgos Keramidas <keramida@FreeBSD.ORG>
To:        current@FreeBSD.ORG
Subject:   Re: mergemaster(8) broken -- uses Perl
Message-ID:  <20020519022922.GA10039@hades.hell.gr>
In-Reply-To: <20020518115410.A33493@dragon.nuxi.com>
References:  <20020518115410.A33493@dragon.nuxi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

Any ideas?  I am not really sure I like something like:

	% /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\
	awk -v mode=0 '{
		if (match($0, "^.r........")) { mode += 00400; }
		if (match($0, "^..w.......")) { mode += 00200; }
		if (match($0, "^...S......")) { mode += 04000; }
		if (match($0, "^...s......")) { mode += 04100; }
		if (match($0, "^...x......")) { mode += 00100; }
		if (match($0, "^....r.....")) { mode += 00040; }
		if (match($0, "^.....w....")) { mode += 00020; }
		if (match($0, "^......S...")) { mode += 02000; }
		if (match($0, "^......s...")) { mode += 02010; }
		if (match($0, "^......x...")) { mode += 00010; }
		if (match($0, "^.......r..")) { mode += 00004; }
		if (match($0, "^........w.")) { mode += 00002; }
		if (match($0, "^.........T")) { mode += 01000; }
		if (match($0, "^.........t")) { mode += 01001; }
		if (match($0, "^.........x")) { mode += 00001; }
	}
	END { printf "0%o\n", mode; }'

[ The above should print in stdout just 01777 as a number. ]

It seems to work, but it's a bit ugly for my taste.  Plus it will
break if the permission bits ever change representation (although this
is unlikely to happen any time real soon).

Does anyone know of any other (possibly more elegant way) of reading
the numeric value of the permission bits for a file?

-- 
Giorgos Keramidas    - http://www.FreeBSD.org
keramida@FreeBSD.org - The Power to Serve

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?20020519022922.GA10039>