summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-01-20 09:19:39 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2012-01-20 09:22:06 +0100
commit01bab6e26d8c2da615cad18003d1ae31a4fb1672 (patch)
treee004b9a10810104dc21d3d40de42c80de3d0ef77
parent2419e5026e52eeaa38011efbb9f34a61a13c28e8 (diff)
downloadabuild-01bab6e26d8c2da615cad18003d1ae31a4fb1672.tar.gz
abuild-01bab6e26d8c2da615cad18003d1ae31a4fb1672.tar.bz2
abuild-01bab6e26d8c2da615cad18003d1ae31a4fb1672.tar.xz
abuild-01bab6e26d8c2da615cad18003d1ae31a4fb1672.zip
abuild: implement locking of downloaded files
We need locking Since the build servers use a shared download dir and multiple vservers might want download same file at same time. fixes #873
-rwxr-xr-xabuild.in20
1 files changed, 19 insertions, 1 deletions
diff --git a/abuild.in b/abuild.in
index 4437877..65778d1 100755
--- a/abuild.in
+++ b/abuild.in
@@ -86,6 +86,9 @@ cleanup() {
msg "Uninstalling dependencies..."
$SUDO $APK del --quiet $apk_opt_wait $uninstall_after
fi
+ if [ -n "$CLEANUP_FILES" ]; then
+ rm -f $CLEANUP_FILES
+ fi
}
die() {
@@ -258,7 +261,8 @@ uri_fetch() {
local d="${uri##*/}" # $(basename $uri)
local opts
[ -n "$quiet" ] && opts="-s"
- [ -f "$SRCDEST/$d" ] && return 0
+
+ local lockfile="$SRCDEST/$d".lock
# fix saveas-*://* URIs
case "$uri" in
@@ -272,6 +276,14 @@ uri_fetch() {
esac
mkdir -p "$SRCDEST"
+
+ CLEANUP_FILES="$CLEANUP_FILES $lockfile"
+ (
+ flock -n -x 200 || msg "Waiting for ${lockfile##*/}..."
+ flock -w 600 -x 200
+
+ [ -f "$SRCDEST/$d" ] && exit 0 # use exit since its a subshell
+
if [ -f "$SRCDEST/$d.part" ]; then
msg "Partial download found. Trying to resume"
opts="$opts -C -"
@@ -289,6 +301,12 @@ uri_fetch() {
$fetcher $opts -o "$SRCDEST/$d.part" "$uri" \
&& mv "$SRCDEST/$d.part" "$SRCDEST/$d"
+
+ ) 200>$lockfile
+
+ local rc=$?
+ rm -f "$lockfile"
+ return $rc
}
is_remote() {