From owner-svn-src-stable@FreeBSD.ORG Mon Dec 27 23:46:48 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1DD101065672; Mon, 27 Dec 2010 23:46:48 +0000 (UTC) (envelope-from wollman@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0BD728FC18; Mon, 27 Dec 2010 23:46:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBRNklCd040083; Mon, 27 Dec 2010 23:46:47 GMT (envelope-from wollman@svn.freebsd.org) Received: (from wollman@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBRNklbL040080; Mon, 27 Dec 2010 23:46:47 GMT (envelope-from wollman@svn.freebsd.org) Message-Id: <201012272346.oBRNklbL040080@svn.freebsd.org> From: Garrett Wollman Date: Mon, 27 Dec 2010 23:46:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216745 - stable/8/usr.bin/locate/locate X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Dec 2010 23:46:48 -0000 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