Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/remote.inc.sh
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2019-01-27 14:39:11 -0500
committerDave Reisner <dreisner@archlinux.org>2019-01-27 14:39:11 -0500
commit205331f5cc20f6d08ef6846721a3c5932a148ed9 (patch)
treeeabfa6bdad3662a2a5ff8b0b45ed1389f0950b55 /remote.inc.sh
parenta06ffad5fdd90d5d28611732ef22a02d5760e7c9 (diff)
Flush the cache on upgrades of asp
This makes the cache an implementation detail which we can freely change version to version.
Diffstat (limited to 'remote.inc.sh')
-rw-r--r--remote.inc.sh22
1 files changed, 20 insertions, 2 deletions
diff --git a/remote.inc.sh b/remote.inc.sh
index 226d566..2c39a55 100644
--- a/remote.inc.sh
+++ b/remote.inc.sh
@@ -8,13 +8,31 @@ __remote_refcache_update() {
awk '{ sub(/refs\/heads\//, "", $2); print $2 }' >"$cachefile"
}
-__remote_refcache_get() {
- local remote=$1 ttl=3600 now cachetime cachefile=$ASPCACHE/remote-$remote
+__remote_refcache_is_stale() {
+ local now cachetime cachefile=$1 ttl=3600
printf -v now '%(%s)T' -1
+ # The cache is stale if we've exceeded the TTL.
if ! cachetime=$(stat -c %Y "$cachefile" 2>/dev/null) ||
(( now > (cachetime + ttl) )); then
+ return 0
+ fi
+
+ # We also consider the cache to be stale when this script is newer than the
+ # cache. This allows upgrades to asp to implicitly wipe the cache and not
+ # make any guarantees about the file format.
+ if (( $(stat -c %Y "${BASH_SOURCE[0]}" 2>/dev/null) > cachetime )); then
+ return 0
+ fi
+
+ return 1
+}
+
+__remote_refcache_get() {
+ local remote=$1 cachefile=$ASPCACHE/remote-$remote
+
+ if __remote_refcache_is_stale "$cachefile"; then
__remote_refcache_update "$remote"
fi