Subject: Re: Let "locate" search/index network volumes, too?
To: None <tech-userlevel@netbsd.org>
From: ITOH Yasufumi <itohy@netbsd.org>
List: tech-userlevel
Date: 02/03/2004 18:31:21
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <7140.1075800460.1@tp.my.domain>
Content-Transfer-Encoding: 7bit

fredb@immanent.net writes:
> Below are my patches to make the locate database construction
> configurable in "/etc/weekly.conf". I use this to index the files of
> the nfs server on the faster workstation, where I'm normally logged
> in. The settings look like this:
> 
> rebuild_locatedb=YES	locatedb_flags="-local +cd9660 +fdesc +kernfs +procfs"
> 			# locatedb_flags="-ffs -nfs"

I have similar patch. :)

Mine can configure
	- filesystem types to ignore,
	- search path (base directory),
	- directories to ignore, and
	- temporary directory
in /etc/locate.conf .

Here're sample /etc/locate.conf and the patch.
Is this useful for anyone?
-- 
ITOH Yasufumi

------- =_aaaaaaaaaa0
Content-Type: text/plain; name="locate.conf.example"; charset="us-ascii"
Content-ID: <7140.1075800460.2@tp.my.domain>
Content-Description: sample /etc/locate.conf
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="locate.conf.example"

#	$NetBSD$

#		 argument    description			default
# searchpath	 <paths>     search path			/
# ignorefs	 <fs types>  ignore filesystems of the types	!local cd9660
#			Setting <fs types> to "none"		fdesc kernfs
#			disables it (search everything).	procfs
#			Prepending ! negates the meaning
#			(ignore if the fs is not the type).
# ignore	 <paths>     ignore dir and the contents	(none)
# ignorecontents <paths>     ignore contents of dir		(none)
# workdir	 <path>	     work directory			/tmp
#
# Multiple "searchpath", "ignore", and "ignorecontents" are allowed.
# *, ?, and [...] pattern can be used for "ignore" and "ignorecontents".
# Note that the meta-characters may match to slashes.  See find(1) for
# the detail of the pattern.

#workdir 	/var/tmp
#searchpath	/
#ignorefs	none
#ignorefs	!local cd9660 fdesc kernfs procfs
#ignore		/tmp /amd
#ignorecontents	/var/wwwoffle/[lmop]* /var/wwwoffle/*tp/*
#ignorecontents	*/.netscape/cache */Mail

------- =_aaaaaaaaaa0
Content-Type: text/plain; name="updatedb.sh.patch"; charset="us-ascii"
Content-ID: <7140.1075800460.3@tp.my.domain>
Content-Description: patch to updatedb.sh
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="updatedb.sh.patch"

Index: updatedb.sh
===================================================================
RCS file: /cvsroot/src/usr.bin/locate/locate/updatedb.sh,v
retrieving revision 1.7
diff -u -r1.7 updatedb.sh
--- updatedb.sh	5 May 2002 07:27:35 -0000	1.7
+++ updatedb.sh	3 Feb 2004 09:26:52 -0000
@@ -39,12 +39,92 @@
 #	@(#)updatedb.csh	8.4 (Berkeley) 10/27/94
 #
 
-SRCHPATHS="/"				# directories to be put in the database
 LIBDIR="/usr/libexec"			# for subprograms
 					# for temp files
+TMPDIR=/tmp
 FCODES="/var/db/locate.database"	# the database
+CONF=/etc/locate.conf			# configuration file
 
 PATH="/bin:/usr/bin"
+
+ignorefs_default='! -fstype local -o -fstype cd9660 -o -fstype fdesc -o -fstype kernfs -o -fstype procfs'
+ignorefs=unset
+ignore=
+SRCHPATHS=
+
+if [ -f "$CONF" ]; then
+	exec 5<&0 < "$CONF"
+	while read com args; do
+		case "$com/$args" in /) continue;; esac	# skip blank lines
+		case "$com" in
+		'#'*)	;;			# lines start with # is comment
+		searchpath)
+			SRCHPATHS="$SRCHPATHS $args";;
+		ignorefs)
+			for i in $args; do
+				case "$args" in
+				none)	ignorefs=;;
+				*)	fs=`echo "$i" | sed -e 's/^!/! -fstype /' -e t -e 's/^/-fstype /'`
+					case "$ignorefs" in
+					''|unset)
+						ignorefs="$fs";;
+					*)	ignorefs="$ignorefs -o $fs";;
+					esac;;
+				esac
+			done;;
+		ignore)
+			set -f
+			for i in $args; do
+				case "$ignore" in
+				'')	;;
+				*)	ignore="$ignore -o";;
+				esac
+				ignore="$ignore -path $i"
+			done
+			set +f;;
+		ignorecontents)
+			set -f
+			for i in $args; do
+				case "$ignore" in
+				'')	;;
+				*)	ignore="$ignore -o";;
+				esac
+				ignore="$ignore -path $i -print"
+			done
+			set +f;;
+		workdir)
+			if [ -d "$args" ]; then
+				TMPDIR="$args"
+			else
+				echo "$CONF: workdir: $args nonexistent" >&2
+			fi;;
+		*)
+			echo "$CONF: $com: unknown config command"	>&2
+			exit 1;;
+		esac
+	done
+	exec <&5 5>&-
+fi
+
+# default value when "search" is absent
+case "$ignorefs" in
+unset)	ignorefs=$ignorefs_default;;
+esac
+
+: ${SRCHPATHS:=/}			# directories to be put in the database
+export TMPDIR
+
+case "$ignorefs/$ignore" in
+/)	lp= ;   rp= ;;
+*)	lp='('; rp=') -prune -o' ;;
+esac
+
+# insert '-o' if neither $ignorefs or $ignore are empty
+case "$ignorefs $ignore" in
+' '*|*' ')	;;
+*)		ignore="-o $ignore";;
+esac
+
 FILELIST=`mktemp -t locate.list` || exit 1
 trap "rm -f '$FILELIST'" EXIT
 trap "rm -f '$FILELIST'; exit 1" INT QUIT TERM
@@ -52,16 +132,8 @@
 # Make a file list and compute common bigrams.
 # Entries of each directory shall be sorted (find -s).
 
-# search locally or everything
-# find -s $SRCHPATHS -print \
-find -s $SRCHPATHS \( \
-    ! -fstype local	\
-    -o -fstype cd9660	\
-    -o -fstype fdesc	\
-    -o -fstype kernfs	\
-    -o -fstype procfs	\
-    \) -a -prune -o -print \
-	>> "$FILELIST"
+set -f
+find -s ${SRCHPATHS} $lp $ignorefs $ignore $rp -print >> "$FILELIST"
 
 BIGRAMS=`$LIBDIR/locate.bigram <"$FILELIST"`
 

------- =_aaaaaaaaaa0--