Date: Mon, 1 Nov 2010 02:20:18 +0000 (UTC) From: Garrett Wollman <wollman@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r214615 - head/usr.bin/locate/locate Message-ID: <201011010220.oA12KIEc021003@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: wollman Date: Mon Nov 1 02:20:18 2010 New Revision: 214615 URL: http://svn.freebsd.org/changeset/base/214615 Log: Style cleanup: make this look more like a 21st-century shell script and not something out of the early 1980s. Make sure all error messages go to stderr, not stdout. Since there's error-handling code to handle empty SEARCHPATHS and FILESYSTEMS, use the initialization form that allows this error to be diagnosed. (hat tip: jilles@) Modified: head/usr.bin/locate/locate/updatedb.sh Modified: head/usr.bin/locate/locate/updatedb.sh ============================================================================== --- head/usr.bin/locate/locate/updatedb.sh Mon Nov 1 01:55:15 2010 (r214614) +++ head/usr.bin/locate/locate/updatedb.sh Mon Nov 1 02:20:18 2010 (r214615) @@ -50,18 +50,20 @@ PATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; ex : ${mklocatedb:=locate.mklocatedb} # make locate database program : ${FCODES:=/var/db/locate.database} # the database -: ${SEARCHPATHS:="/"} # directories to be put in the database -: ${PRUNEPATHS:="/tmp /usr/tmp /var/tmp /var/db/portsnap"} # unwanted directories +: ${SEARCHPATHS="/"} # directories to be put in the database +: ${PRUNEPATHS="/tmp /usr/tmp /var/tmp /var/db/portsnap"} # unwanted directories : ${PRUNEDIRS=".zfs"} # unwanted directories, in any parent -: ${FILESYSTEMS:="$(lsvfs | tail -n +3 | \ +: ${FILESYSTEMS="$(lsvfs | tail -n +3 | \ egrep -vw "loopback|network|synthetic|read-only|0" | \ cut -d " " -f1)"} # allowed filesystems : ${find:=find} -case X"$SEARCHPATHS" in - X) echo "$0: empty variable SEARCHPATHS"; exit 1;; esac -case X"$FILESYSTEMS" in - X) echo "$0: empty variable FILESYSTEMS"; exit 1;; esac +if [ -z "$SEARCHPATHS" ]; then + echo "$0: empty variable SEARCHPATHS" >&2; exit 1 +fi +if [ -z "$FILESYSTEMS" ]; then + echo "$0: empty variable FILESYSTEMS" >&2; exit 1 +fi # Make a list a paths to exclude in the locate run excludes="! (" or="" @@ -72,33 +74,29 @@ do done excludes="$excludes ) -prune" -case X"$PRUNEPATHS" in - X) ;; - *) for path in $PRUNEPATHS - do +if [ -n "$PRUNEPATHS" ]; then + for path in $PRUNEPATHS; do excludes="$excludes -or -path $path -prune" - done;; -esac + done +fi -case X"$PRUNEDIRS" in - X) ;; - *) for dir in $PRUNEDIRS - do +if [ -n "$PRUNEDIRS" ]; then + for dir in $PRUNEDIRS; do excludes="$excludes -or -name $dir -type d -prune" - done;; -esac + done +fi tmp=$TMPDIR/_updatedb$$ trap 'rm -f $tmp; rmdir $TMPDIR' 0 1 2 3 5 10 15 # search locally -# echo $find $SEARCHPATHS $excludes -or -print && exit if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null | $mklocatedb -presort > $tmp then - case X"`$find $tmp -size -257c -print`" in - X) cat $tmp > $FCODES;; - *) echo "updatedb: locate database $tmp is empty" - exit 1 - esac + if [ -n "$($find $tmp -size -257c -print)" ]; then + echo "updatedb: locate database $tmp is empty" >&2 + exit 1 + else + cat $tmp > $FCODES # should be cp? + fi fi
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011010220.oA12KIEc021003>