diff options
author | Dave Reisner <dreisner@archlinux.org> | 2017-11-18 08:14:00 -0500 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2017-11-18 08:28:11 -0500 |
commit | 22f079869b7586bcef4b77b6601376be2bd1e61d (patch) | |
tree | 3a8feb4fbd9b55276dd7d50437bb12028616fd2d | |
parent | c9dfb6dc724d8d2d79d525620566e3f188d72310 (diff) | |
download | asp32-22f079869b7586bcef4b77b6601376be2bd1e61d.tar.xz |
Avoid corrupting caches when network is unavailable
This removes the use of a tempfile entirely, and only updates the cache
when `git ls-remote` succeeds.
Based on a PR by polygamma:
https://github.com/falconindy/asp/pull/20
-rw-r--r-- | remote.inc.sh | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/remote.inc.sh b/remote.inc.sh index 01031e0..226d566 100644 --- a/remote.inc.sh +++ b/remote.inc.sh @@ -1,12 +1,11 @@ __remote_refcache_update() { - local remote=$1 cachefile=$ASPCACHE/remote-$remote + local remote=$1 cachefile=$ASPCACHE/remote-$remote refs - # shellcheck disable=SC2064 - trap "rm -f '$cachefile~'" RETURN + refs=$(git ls-remote "$remote" 'refs/heads/packages/*') || + log_fatal "failed to update remote $remote" - git ls-remote "$remote" 'refs/heads/packages/*' | - awk '{ sub(/refs\/heads\//, "", $2); print $2 }' >"$cachefile~" && - mv "$cachefile"{~,} + printf '%s' "$refs" | + awk '{ sub(/refs\/heads\//, "", $2); print $2 }' >"$cachefile" } __remote_refcache_get() { |