summary refs log tree commit diff
path: root/xlocate
diff options
context:
space:
mode:
Diffstat (limited to 'xlocate')
-rwxr-xr-xxlocate21
1 files changed, 15 insertions, 6 deletions
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