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 23:50:37 +0300
committerLevente Polyak <anthraxx@archlinux.org>2021-06-16 23:37:10 +0200
commit385b47e56e0f1edf9fc36f75febf3f0622a9a251 (patch)
treee6d4a98de90ab4debab7384c70cbbbef590eb4f8
parent9d39abbefee64191c63c7f306d4656d620b0ba78 (diff)
sogrep: refresh if any database is over a day old
Outdated sogrep cache has already bit us once in the past. Finding one or more databases older than a day is a good indication that a refresh is in order, so do that automatically.
-rwxr-xr-xsogrep.in21
1 files changed, 20 insertions, 1 deletions
diff --git a/sogrep.in b/sogrep.in
index 19fe651..676d9df 100755
--- a/sogrep.in
+++ b/sogrep.in
@@ -54,6 +54,24 @@ recache() {
done
}
+is_outdated_cache() {
+ local repo arch
+
+ # links databases are generated at about the same time every day; we should
+ # attempt to check for new database files if any of them are over a day old
+
+ for repo in "${_repos[@]}"; do
+ for arch in "${arches[@]}"; do
+ local dbpath=${SOCACHE_DIR}/${arch}/${repo}.links.tar.gz
+ if [[ ! -f ${dbpath} ]] || [[ $(find "${dbpath}" -mtime +0) ]]; then
+ return 0
+ fi
+ done
+ done
+
+ return 1
+}
+
search() {
local repo=$1 arch lib=$2 srepos=("${_repos[@]}")
@@ -152,7 +170,8 @@ if ! (( ( REFRESH && $# == 0 ) || $# == 2 )); then
exit 1
fi
-if (( REFRESH )) || [[ ! -d ${SOCACHE_DIR} ]]; then
+# trigger a refresh if requested explicitly or the cached dbs might be outdated
+if (( REFRESH )) || [[ ! -d ${SOCACHE_DIR} ]] || is_outdated_cache; then
recache
(( $# == 2 )) || exit 0
fi