summaryrefslogtreecommitdiff
path: root/remote.inc.sh
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-08-30 11:52:52 -0400
committerDave Reisner <dreisner@archlinux.org>2014-08-30 11:52:52 -0400
commite3dc5f7cb77942fdac1fa02ee41669341bd7b67b (patch)
tree7ecb41a6f1d50f4d0e46c77783b857122ad8d342 /remote.inc.sh
parent5997ed5aae975f3b1fc74af0797db9c01345114a (diff)
downloadasp32-e3dc5f7cb77942fdac1fa02ee41669341bd7b67b.tar.xz
abstract away cache semantics
Diffstat (limited to 'remote.inc.sh')
-rw-r--r--remote.inc.sh33
1 files changed, 14 insertions, 19 deletions
diff --git a/remote.inc.sh b/remote.inc.sh
index 81f2935..ba72565 100644
--- a/remote.inc.sh
+++ b/remote.inc.sh
@@ -1,20 +1,5 @@
declare -A refcache=()
-__remote_refcache_get() {
- local remote=$1 ttl=3600 now= cachetime= cachefile=$ASPCACHE/remote-$remote
-
- # miss
- cachetime=$(stat -c %Y "$cachefile" 2>/dev/null) || return 1
-
- printf -v now '%(%s)T' -1
-
- # miss
- (( now > (cachetime + ttl) )) && return 1
-
- # hit
- mapfile -t "$2" <"$cachefile"
-}
-
__remote_refcache_update() {
local remote=$1 cachefile=$ASPCACHE/remote-$remote
@@ -25,13 +10,23 @@ __remote_refcache_update() {
mv "$cachefile"{~,}
}
-remote_get_all_refs() {
- local remote=$1
+__remote_refcache_get() {
+ local remote=$1 ttl=3600 now= cachetime= cachefile=$ASPCACHE/remote-$remote
+
+ printf -v now '%(%s)T' -1
- if ! __remote_refcache_get "$remote" "$2"; then
+ if ! cachetime=$(stat -c %Y "$cachefile" 2>/dev/null) ||
+ (( now > (cachetime + ttl) )); then
__remote_refcache_update "$remote"
- __remote_refcache_get "$remote" "$2"
fi
+
+ mapfile -t "$2" <"$cachefile"
+}
+
+remote_get_all_refs() {
+ local remote=$1
+
+ __remote_refcache_get "$remote" "$2"
}
remote_has_package() {