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
This commit is contained in:
parent
2419e5026e
commit
01bab6e26d
20
abuild.in
20
abuild.in
@ -86,6 +86,9 @@ cleanup() {
|
|||||||
msg "Uninstalling dependencies..."
|
msg "Uninstalling dependencies..."
|
||||||
$SUDO $APK del --quiet $apk_opt_wait $uninstall_after
|
$SUDO $APK del --quiet $apk_opt_wait $uninstall_after
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$CLEANUP_FILES" ]; then
|
||||||
|
rm -f $CLEANUP_FILES
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
@ -258,7 +261,8 @@ uri_fetch() {
|
|||||||
local d="${uri##*/}" # $(basename $uri)
|
local d="${uri##*/}" # $(basename $uri)
|
||||||
local opts
|
local opts
|
||||||
[ -n "$quiet" ] && opts="-s"
|
[ -n "$quiet" ] && opts="-s"
|
||||||
[ -f "$SRCDEST/$d" ] && return 0
|
|
||||||
|
local lockfile="$SRCDEST/$d".lock
|
||||||
|
|
||||||
# fix saveas-*://* URIs
|
# fix saveas-*://* URIs
|
||||||
case "$uri" in
|
case "$uri" in
|
||||||
@ -272,6 +276,14 @@ uri_fetch() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
mkdir -p "$SRCDEST"
|
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
|
if [ -f "$SRCDEST/$d.part" ]; then
|
||||||
msg "Partial download found. Trying to resume"
|
msg "Partial download found. Trying to resume"
|
||||||
opts="$opts -C -"
|
opts="$opts -C -"
|
||||||
@ -289,6 +301,12 @@ uri_fetch() {
|
|||||||
|
|
||||||
$fetcher $opts -o "$SRCDEST/$d.part" "$uri" \
|
$fetcher $opts -o "$SRCDEST/$d.part" "$uri" \
|
||||||
&& mv "$SRCDEST/$d.part" "$SRCDEST/$d"
|
&& mv "$SRCDEST/$d.part" "$SRCDEST/$d"
|
||||||
|
|
||||||
|
) 200>$lockfile
|
||||||
|
|
||||||
|
local rc=$?
|
||||||
|
rm -f "$lockfile"
|
||||||
|
return $rc
|
||||||
}
|
}
|
||||||
|
|
||||||
is_remote() {
|
is_remote() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user