sogrep: store unextracted *.links.tar.gz databases

Extracting these databases is painfully slow on HDDs (especially laptop
ones). There shouldn't be a drawback to keeping the tarballs around and
extracting them to a temporary directory (usually tmpfs) to parse them.

The implemented update logic tries to avoid redownloading unchanged dbs.
This commit is contained in:
Evangelos Foutras 2020-05-07 21:38:38 +03:00 committed by Levente Polyak
parent 90ba07d9be
commit 9d39abbefe
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 19 additions and 6 deletions

View File

@ -18,6 +18,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
m4_include(lib/common.sh)
# globals
: ${SOLINKS_MIRROR:="https://mirror.pkgbuild.com"}
: ${SOCACHE_DIR:="${XDG_CACHE_HOME:-${HOME}/.cache}/sogrep"}
@ -39,9 +41,15 @@ recache() {
for repo in "${_repos[@]}"; do
for arch in "${arches[@]}"; do
# delete extracted tarballs from previous sogrep versions
rm -rf "${SOCACHE_DIR}/${arch}/${repo}"
mkdir -p "${SOCACHE_DIR}/${arch}/${repo}"
curl -L "$verbosity" "${SOLINKS_MIRROR}/${repo}/os/${arch}/${repo}.links.tar.gz" | bsdtar -xf - -C "${SOCACHE_DIR}/${arch}/${repo}"
# fetch repo links database if newer than our cached copy
local dbpath=${SOCACHE_DIR}/${arch}/${repo}.links.tar.gz
mkdir -p "${dbpath%/*}"
(( VERBOSE )) && echo "Fetching ${repo}.links.tar.gz..."
curl -LR "${verbosity}" -o "${dbpath}" -z "${dbpath}" \
"${SOLINKS_MIRROR}/${repo}/os/${arch}/${repo}.links.tar.gz"
done
done
}
@ -58,15 +66,20 @@ search() {
srepos=("${repo}")
fi
setup_workdir
for arch in "${arches[@]}"; do
for repo in "${srepos[@]}"; do
local prefix=
(( VERBOSE && ${#srepos[@]} > 1 )) && prefix=${repo}/
db=${SOCACHE_DIR}/${arch}/${repo}/
if [[ -d ${db} ]]; then
local db=${SOCACHE_DIR}/${arch}/${repo}.links.tar.gz
if [[ -f ${db} ]]; then
local extracted=${WORKDIR}/${arch}/${repo}
mkdir -p "${extracted}"
bsdtar -C "${extracted}" -xf "${db}"
while read -rd '' pkg; do
read -r match
pkg=${pkg#${db}}
pkg=${pkg#${extracted}/}
pkg="${prefix}${pkg%-*-*/links}"
if (( VERBOSE )); then
@ -74,7 +87,7 @@ search() {
else
printf '%s\n' "${pkg}"
fi
done < <(grep -rZ "${lib}" "${db}") | sort -u
done < <(grep -rZ "${lib}" "${extracted}") | sort -u
fi
done
done | resort