only bother with leaf nodes, smaller but slower?
also error message when package not found also correctly prepend $PREFIX on reverse mode
This commit is contained in:
parent
96a9fd100a
commit
cf66897fe7
|
@ -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
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…
Reference in New Issue