Skip to content

Commit

Permalink
bee-query: Use canonical names in file search
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed May 14, 2024
1 parent 3cfe004 commit 47b4ba8
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/bee-query.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${@}"
Expand Down Expand Up @@ -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
}


Expand Down

0 comments on commit 47b4ba8

Please sign in to comment.