svn commit: r214615 - head/usr.bin/locate/locate
Garrett Wollman
wollman at FreeBSD.org
Mon Nov 1 02:20:19 UTC 2010
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
More information about the svn-src-head
mailing list