summaryrefslogtreecommitdiffstats
path: root/abuild.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-08-26 08:14:36 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-08-26 16:44:23 +0200
commit92186b70ca9c520fc726e0885aac633aadace655 (patch)
treeddef3fcf99f329dc62294dfafc111d350cfa2e50 /abuild.in
parentbed1c80a465683a34063acd78ef3d86a8e196296 (diff)
downloadabuild-92186b70ca9c520fc726e0885aac633aadace655.tar.bz2
abuild-92186b70ca9c520fc726e0885aac633aadace655.tar.xz
abuild: fix fetch lock file on nfs
flock(2) on an NFS mount will on the server side convert the lock to a POSIX lock (fcntl(F_SETLK)). This means that abuild running on NFS server and client will create different locks and they will both try download same file at same time. We fix this by creating a small abuild-fetch application that will create a POSIX lock which works with NFS.
Diffstat (limited to 'abuild.in')
-rw-r--r--abuild.in69
1 files changed, 1 insertions, 68 deletions
diff --git a/abuild.in b/abuild.in
index b8d8851..952048b 100644
--- a/abuild.in
+++ b/abuild.in
@@ -298,79 +298,12 @@ sourcecheck() {
return 0
}
-# convert curl options to wget options and call wget instead of curl
-wget_fallback() {
- local wget_opts= outfile= opt=
- while getopts "C:Lko:s" opt; do
- case $opt in
- 'L') ;; # --location. wget does this by default
- 'f') ;; # --fail. wget does this by default
- 'C') wget_opts="$wget_opts -c";; # --continue-at
- 's') wget_opts="$wget_opts -q";; # --silent
- 'o') wget_opts="$wget_opts -O $OPTARG";; # --output
- 'k') wget_opts="$wget_opts --no-check-certificate";; #gnu wget
- esac
- done
- shift $(( $OPTIND - 1 ))
- wget $wget_opts "$1"
-}
-
uri_fetch() {
local uri="$1"
- local d="${uri##*/}" # $(basename $uri)
- local opts
[ -n "$quiet" ] && opts="-s"
- local lockfile="$SRCDEST/$d".lock
-
- # fix saveas-*://* URIs
- case "$uri" in
- # remove 'saveas-' from beginning and
- # '/filename' from end of URI
- saveas-*://*) uri="${uri:7:$(expr ${#uri} - 7 - ${#d} - 1)}";;
-
- *::*)
- d=${uri%%::*}
- uri=${uri#$d::}
- ;;
- esac
-
- case "$uri" in
- https://*) opts="-k";;
- esac
-
mkdir -p "$SRCDEST"
-
- CLEANUP_FILES="$CLEANUP_FILES $lockfile"
- (
- flock -n -x 9 || msg "Waiting for ${lockfile##*/}..."
- flock -x 9
-
- [ -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 -"
- fi
- msg "Fetching $uri"
-
- # fallback to wget if curl is missing. useful for bootstrapping
- local fetcher=
- if ! [ -x "$(which curl)" ]; then
- fetcher=wget_fallback
- else
- fetcher=curl
- opts="$opts -L -f -k"
- fi
-
- $fetcher $opts -o "$SRCDEST/$d.part" "$uri" \
- && mv "$SRCDEST/$d.part" "$SRCDEST/$d"
-
- ) 9>$lockfile
-
- local rc=$?
- rm -f "$lockfile"
- return $rc
+ abuild-fetch -d "$SRCDEST" "$uri"
}
is_remote() {