svn commit: r216745 - stable/8/usr.bin/locate/locate
Garrett Wollman
wollman at FreeBSD.org
Mon Dec 27 23:46:48 UTC 2010
Author: wollman
Date: Mon Dec 27 23:46:47 2010
New Revision: 216745
URL: http://svn.freebsd.org/changeset/base/216745
Log:
Merge three revisions from head:
r214583 | wollman | 2010-10-30 22:36:05 -0400 (Sat, 30 Oct 2010) | 6 lines
Changed paths:
M /head/usr.bin/locate/locate/locate.rc
M /head/usr.bin/locate/locate/updatedb.sh
Make it possible to exclude directories by name no matter where they
are in the filesystem from the locate database. By default, exclude
".zfs" directories, as users who who have set snapdir=visible and are
taking frequent snapshots most likely do not want the snapshots
included in the locate database.
------------------------------------------------------------------------
r214613 | wollman | 2010-10-31 21:51:47 -0400 (Sun, 31 Oct 2010) | 7 lines
Changed paths:
M /head/usr.bin/locate/locate/updatedb.sh
jilles@ pointed out that using ${PRUNEDIRS:=".zfs"} in updatedb.sh
made it impossible to override PRUNEDIRS to make it empty. Use the
non-colon form to only set PRUNEDIRS if it is completely unset. (For
parallelism, the other configuration defaults here could be done the
same way, but that could be more obviously accomplished by disabling
updatedb in periodic.conf, so leave them alone for now.)
------------------------------------------------------------------------
r214615 | wollman | 2010-10-31 22:20:18 -0400 (Sun, 31 Oct 2010) | 6 lines
Changed paths:
M /head/usr.bin/locate/locate/updatedb.sh
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:
stable/8/usr.bin/locate/locate/locate.rc
stable/8/usr.bin/locate/locate/updatedb.sh
Directory Properties:
stable/8/usr.bin/locate/ (props changed)
Modified: stable/8/usr.bin/locate/locate/locate.rc
==============================================================================
--- stable/8/usr.bin/locate/locate/locate.rc Mon Dec 27 22:52:47 2010 (r216744)
+++ stable/8/usr.bin/locate/locate/locate.rc Mon Dec 27 23:46:47 2010 (r216745)
@@ -15,9 +15,12 @@
# directories to be put in the database
#SEARCHPATHS="/"
-# directories unwanted in output
+# paths unwanted in output
#PRUNEPATHS="/tmp /usr/tmp /var/tmp /var/db/portsnap"
+# directories unwanted in output
+#PRUNEDIRS=".zfs"
+
# filesystems allowed. Beware: a non-listed filesystem will be pruned
# and if the SEARCHPATHS starts in such a filesystem locate will build
# an empty database.
Modified: stable/8/usr.bin/locate/locate/updatedb.sh
==============================================================================
--- stable/8/usr.bin/locate/locate/updatedb.sh Mon Dec 27 22:52:47 2010 (r216744)
+++ stable/8/usr.bin/locate/locate/updatedb.sh Mon Dec 27 23:46:47 2010 (r216745)
@@ -50,17 +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
-: ${FILESYSTEMS:="$(lsvfs | tail -n +3 | \
+: ${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 | \
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=""
@@ -71,25 +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
+
+if [ -n "$PRUNEDIRS" ]; then
+ for dir in $PRUNEDIRS; do
+ excludes="$excludes -or -name $dir -type d -prune"
+ 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-stable
mailing list