From owner-freebsd-current Sat May 18 19:29:33 2002 Delivered-To: freebsd-current@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 472BF37B40C for ; Sat, 18 May 2002 19:29:28 -0700 (PDT) Received: from hades.hell.gr (patr530-b181.otenet.gr [212.205.244.189]) by mailsrv.otenet.gr (8.12.3/8.12.3) with ESMTP id g4J2TPQJ016480 for ; Sun, 19 May 2002 05:29:26 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.3/8.12.3) with ESMTP id g4J2TOIu010302 for ; Sun, 19 May 2002 05:29:24 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from charon@localhost) by hades.hell.gr (8.12.3/8.12.3/Submit) id g4J2TOvV010301 for current@FreeBSD.ORG; Sun, 19 May 2002 05:29:24 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sun, 19 May 2002 05:29:22 +0300 From: Giorgos Keramidas To: current@FreeBSD.ORG Subject: Re: mergemaster(8) broken -- uses Perl Message-ID: <20020519022922.GA10039@hades.hell.gr> References: <20020518115410.A33493@dragon.nuxi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020518115410.A33493@dragon.nuxi.com> User-Agent: Mutt/1.3.99i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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