about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-01-08 11:48:46 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-01-08 11:48:46 +0100
commit5637c9384193ab58dd976ac8f388a3547d24489e (patch)
tree1558965bd64fa14ecca2c4639c6a8d52030477d3
parentc820f72b1af215bdb4dd73377ac734722e8ad124 (diff)
downloadxtools-5637c9384193ab58dd976ac8f388a3547d24489e.tar.gz
xtools-5637c9384193ab58dd976ac8f388a3547d24489e.tar.xz
xtools-5637c9384193ab58dd976ac8f388a3547d24489e.zip
xlocate: use -u to create/update database.
-rw-r--r--README2
-rwxr-xr-xxlocate21
2 files changed, 16 insertions, 7 deletions
diff --git a/README b/README
index bca493e..7c2adc3 100644
--- a/README
+++ b/README
@@ -13,7 +13,7 @@ https://github.com/voidlinux/xbps
   xgrep PATTERN PKGS... - search files limited to XBPS package contents
   xlg PKG - open short commit log for XBPS template
   xlint TEMPLATE - scan XBPS template for common mistakes
-  xlocate PATTERN - locate files in all XBPS packages
+  xlocate [-u | PATTERN] - locate files in all XBPS packages
   xlog PKG - open commit log for XBPS template
   xls PKGS... - list files contained in PKGS (including binpkgs)
   xmindep PKGS... - minimize list of PKGS by removing implicit dependencies
diff --git a/xlocate b/xlocate
index 0b34fe0..1b3efff 100755
--- a/xlocate
+++ b/xlocate
@@ -1,14 +1,23 @@
 #!/bin/sh
-# xlocate PATTERN - locate files in all XBPS packages
+# xlocate [-u | PATTERN] - locate files in all XBPS packages
 
 : ${XLOCATE_DB:=~/.cache/xlocate.db}
 
+xupdatedb() {
+	echo "xlocate: reindexing database..." 1>&2
+	xbps-query -Ro '*' |
+		sed 's/ *([^)]*)$//; s|: ||;' |
+		/usr/libexec/frcode >"$XLOCATE_DB"
+}
+
+if [ "$1" = -u ]; then
+	xupdatedb
+	exit $?
+fi
+
 if [ -e "$XLOCATE_DB" ]; then
-	if [ "$XLOCATE_DB" -ot /var/db/xbps/http___repo_voidlinux_eu_current/*-repodata ] || [ ! -s "$XLOCATE_DB" ]; then
-		echo "xlocate: reindexing database..." 1>&2
-		xbps-query --regex -Ro '' |
-			sed 's/ *([^)]*)$//; s|: ||;' |
-			/usr/libexec/frcode >"$XLOCATE_DB"
+	if find /var/db/xbps/ -name '*repodata' -newer "$XLOCATE_DB" | grep -q .; then
+		xupdatedb
 	fi
 	rx=
 	case "$1" in