From 47b4ba888ee50f491306ab373f57d39afd8c6cc6 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 9 May 2024 13:10:05 +0200 Subject: [PATCH] bee-query: Use canonical names in file search When "bee query PATTERN" is used to grep for installed files, use the inventory file and translate the filenames from the inventory to their canonical form, which is the real path, not the path used to install them, possibly following symlinks. The new code is a lot faster than the old one. The wall time for `fakeroot bee query otop` is reduced from 0m11.712s to 0m0.760s. --- src/bee-query.sh.in | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/bee-query.sh.in b/src/bee-query.sh.in index ad4313f..30fe565 100644 --- a/src/bee-query.sh.in +++ b/src/bee-query.sh.in @@ -32,6 +32,9 @@ VERSION=${BEE_VERSION} : ${BEE_BINDIR:=@BINDIR@} : ${BEE_LIBEXECDIR:=@LIBEXECDIR@} +: ${BEEFLOCK=${BEE_BINDIR}/beeflock} +: ${BEECACHE_CACHEDIR=${BEE_CACHEDIR}/bee-cache} +: ${BEECACHE_INVENTORY=${BEECACHE_CACHEDIR}/INVENTORY} function bee-list() { ${BEE_LIBEXECDIR}/bee/bee.d/bee-list "${@}" @@ -81,18 +84,22 @@ function get_files() { } function get_pkgs() { - f=$1 - - for pkg in $(bee-list --installed) ; do - - if egrep -q "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT" ; then - echo ${pkg} - while read line ; do - eval $(${BEESEP} "${line}") - echo " ${file}" - done < <(egrep "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT") - fi - done + file_pattern="$1" + last_pkg='' + + ${BEEFLOCK} --shared ${BEECACHE_INVENTORY} \ + ${BEE_LIBEXECDIR}/bee/beeindextr ${BEECACHE_INVENTORY} | \ + grep -- "$file_pattern" | \ + sort | \ + while read -r pkg mtime uid gid mode size md5 filename; do + if [[ $filename =~ $file_pattern ]]; then + if [ "$pkg" != "$last_pkg" ]; then + echo $pkg + last_pkg="$pkg" + fi + printf " %s\n" "$filename" + fi + done }