Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Jun 2002 00:45:12 +0300
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        dougb@freebsd.org
Cc:        freebsd-current@freebsd.org, freebsd-hackers@freebsd.org
Subject:   Removing perl usage from mergemaster
Message-ID:  <20020605214512.GA16384@hades.hell.gr>

next in thread | raw e-mail | index | archive | help
Hello dougb & all,

Here's a patch that removes all trails of Perl usage from mergemaster.
The parts that I want your careful scrutiny directed at are the new
stat_mode() shell function, and the parts that I have touched lines
removing Perl code.  I have done some testing to the resulting
mergemaster script, mostly by comparing the results of stat_mode() and
the old Perl code (having them both run, and print their output,
before mergemaster calls "exit 1").  If you find that you like the
changes, then the recent mergemaster problems on CURRENT machines that
have no perl port installed will go away ;)

I have tried to keep the code of stat_mode() clean, despite the fact
that it could possibly be written also as:

    #
    # Print in STDOUT the octal mode of a file and/or directory.
    #
    stat_mode () {
            echo $(( ~$(echo "obase=10; ibase=8; ${2}" | bc ) &
                     $( echo "obase=10;ibase=8;07777" | bc ) &
                     $( echo "obase=10; ibase=2; " \
                         $( ls -ld "${1}" | \
                            cut -c2-10 | \
                            sed -e '/^..[sS]/ s/^.*$/&+100000000000/' \
                                -e '/^.....[sS]/ s/^.*$/&+10000000000/' \
                                -e '/^........[tT]/ s/^.*$/&+1000000000/' | \
                            sed -e 's/[st]/x/g' -e 's/ST/-/g' | \
                            sed -e 's/[rwx]/1/g' | \
                            sed -e 's/[^1+]/0/g' ) \
                         | bc )
                  )) | awk '{printf "%04o\n", $0}'
    }   

The ls output parsing was inspired by an old post by Alfred Perlstein,
and I have only added the proper sed-lines to convert it to a valid
binary number.  The rest, shell evaluations, substitutions and all is
something you can safely blame me for.  Until now, I have verified
that this produces the same output, but it's admittedly harder to
decipher than the one I have included in the diff below.  It is still
here, for us to use, if you all feel that it's better to avoid the use
of variables in stat_mode().  Whatever you all feel better with...

I think Doug's opinion as the maintainer of mergemaster is of the
utmost importance here.  Anyone else with a better idea for removing
the dependency of mergemaster on Perl, is welcome to step up and offer
us his assistance though :)

Giorgos.



--- patch begins ---
Index: mergemaster.sh
===================================================================
RCS file: /home/ncvs/src/usr.sbin/mergemaster/mergemaster.sh,v
retrieving revision 1.31
diff -u -r1.31 mergemaster.sh
--- mergemaster.sh	28 May 2002 07:25:44 -0000	1.31
+++ mergemaster.sh	5 Jun 2002 21:25:09 -0000
@@ -214,6 +214,28 @@
   esac
 }
 
+stat_mode () {
+	pathname="$1"
+	confirmed_umask="$2"
+
+	decimal_umask=$( echo "obase=10; ibase=8; ${confirmed_umask}" | bc )
+	binary_mode=$( ls -ld "${pathname}" | \
+		cut -c2-10 | \
+		sed -e '/^..[sS]/ s/^.*$/&+100000000000/' \
+		    -e '/^.....[sS]/ s/^.*$/&+10000000000/' \
+		    -e '/^........[tT]/ s/^.*$/&+1000000000/' | \
+		sed -e 's/[st]/x/g' -e 's/ST/-/g' | \
+		sed -e 's/[rwx]/1/g' | \
+		sed -e 's/[^1+]/0/g' )
+	decimal_mode=$( echo "obase=10; ibase=2; ${binary_mode}" | bc )
+	mode_mask=$( echo "obase=10;ibase=8;07777" | bc )
+	masked_mode=$(( ${mode_mask} & ${decimal_mode} ))
+	umasked_mode=$(( ${masked_mode} & ~${decimal_umask} ))
+	octal_mode=$( echo ${umasked_mode} | awk '{printf "%04o\n", $0}' )
+	unset decimal_umask binary_mode decimal_mode mode_mask masked_mode umasked_mode
+	echo "${octal_mode}"
+}
+
 # Set the default path for the temporary root environment
 #
 TEMPROOT='/var/tmp/temproot'
@@ -641,13 +663,11 @@
   esac
 
   if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
-    DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
-      oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
+    DIR_MODE=`stat_mode "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
     install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
   fi
 
-  FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
-      oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
+  FILE_MODE=`stat_mode "${1}" "${CONFIRMED_UMASK}"`
 
   if [ ! -x "${1}" ]; then
     case "${1#.}" in
--- patch ends ---

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?20020605214512.GA16384>