Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvangelos Foutras <evangelos@foutrelis.com>2020-05-07 21:38:38 +0300
committerLevente Polyak <anthraxx@archlinux.org>2021-06-16 23:37:06 +0200
commit9d39abbefee64191c63c7f306d4656d620b0ba78 (patch)
tree3a7d92be0cec2fc51e33c667b8d42f218a7d023c
parent90ba07d9be2883cccb1dd42aa0c8f974a2ff055c (diff)
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.
-rwxr-xr-xsogrep.in25
1 files changed, 19 insertions, 6 deletions
diff --git a/sogrep.in b/sogrep.in
index ce7b21e..19fe651 100755
--- a/sogrep.in
+++ b/sogrep.in
@@ -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