Browse Source

only bother with leaf nodes, smaller but slower? (#12)

also error message when package not found
also correctly prepend $PREFIX on reverse mode
pull/13/head 2.1.0
Lucy Phipps 10 months ago
committed by GitHub
parent
commit
8fdd508949
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      update-whatprovides-db.sh
  2. 15
      whatprovides

10
update-whatprovides-db.sh

@ -9,9 +9,15 @@ set -e -u
: "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}"
list_files() {
dpkg-deb --fsys-tarfile "${1}" | tar -t | cut -b2- \
FILES=$(dpkg-deb --fsys-tarfile "${1}" | tar -t | cut -b2- \
| xargs -rd\\n realpath -sm --relative-base="$TERMUX_PREFIX" -- \
| grep -vEx '[./]|/data(/data(/com\.termux(/files)?)?)?'
| grep -vEx '[./]|/data(/data(/com\.termux(/files)?)?)?')
SORTKEYS='-k1,1'
for ((x=2; x<=$(wc -L <<< "${FILES//[^\/$'\n']/}")+1; x++)); do
SORTKEYS="$SORTKEYS -k$x,$x"
done
sort -t/ $SORTKEYS <<< "$FILES" \
| awk 'NR == 1 { p=$0; next } substr($0, 1, length(p) +1 ) != p"/" { print p } { p=$0 } END { print p }'
}
write_sql_script() {

15
whatprovides

@ -116,9 +116,17 @@ if ${REVERSE_MODE}; then
exit 1
fi
sqlite3 "${DB_PATH}" \
if ! sqlite3 "${DB_PATH}" \
"SELECT owned_file FROM 'whatprovides' WHERE package_name == '${1}' ORDER BY owned_file" \
| awk "NR == 1 { print \"${1}: /.\\n${1}: /data\\n${1}: /data/data\\n${1}: /data/data/com.termux\\n${1}: /data/data/com.termux/files\\n${1}: ${PREFIX}\" } { print \"${1}: ${PREFIX}/\"\$0 }"
| awk "{ if (substr(\$0, 1, 1) == \"/\") print \"${1}: \"\$0; else print \"${1}: ${PREFIX}/\"\$0 } END { if (NR == 0) exit 1 }"
then
{
echo
echo "Error: package '$1' is not found."
echo
} >&2
exit 1
fi
else
NEWPREFIX=
FILE="$(realpath -sm "$1")"
@ -141,8 +149,9 @@ else
NEWPREFIX="${PREFIX}/"
fi # else FILE is entirely separate from PREFIX (unlikely to be in DB)
FILE_ESC="${FILE//\'/\'\'}"
if ! sqlite3 "${DB_PATH}" \
"SELECT package_name FROM 'whatprovides' WHERE owned_file == '${FILE//\'/\'\'}' ORDER BY package_name" \
"SELECT DISTINCT package_name FROM 'whatprovides' WHERE owned_file == '${FILE_ESC}' OR substr(owned_file, 1, ${#FILE} +1) == '${FILE_ESC}/' ORDER BY package_name" \
| awk "{ print \$0\": ${NEWPREFIX}${FILE}\" } END { if (NR == 0) exit 1 }"
then
{

Loading…
Cancel
Save