aboutsummaryrefslogtreecommitdiff
path: root/reproduce/analysis/bash/download-multi-try
diff options
context:
space:
mode:
authorMohammad Akhlaghi <mohammad@akhlaghi.org>2020-04-02 15:51:28 +0100
committerMohammad Akhlaghi <mohammad@akhlaghi.org>2020-04-02 16:05:03 +0100
commitde3842a14e36b2debb3ad375d95411d15d45dc84 (patch)
tree86ae571f85c639c616cf8939cbcec7f1c1be4c9c /reproduce/analysis/bash/download-multi-try
parent646756675566a0907edf143c6b6950e0479d9e7e (diff)
parentcbf177e09af6b9d240388d148b0cb5e3488d8b09 (diff)
Imported recent work on Maneage, minor conflicts fixed
A few minor conflicts occurred and were fixed.
Diffstat (limited to 'reproduce/analysis/bash/download-multi-try')
-rwxr-xr-xreproduce/analysis/bash/download-multi-try22
1 files changed, 21 insertions, 1 deletions
diff --git a/reproduce/analysis/bash/download-multi-try b/reproduce/analysis/bash/download-multi-try
index dec2539..7a5f8f2 100755
--- a/reproduce/analysis/bash/download-multi-try
+++ b/reproduce/analysis/bash/download-multi-try
@@ -51,11 +51,13 @@ set -e
-# Input arguments and necessary sanity checks.
+# Input arguments and necessary sanity checks. Note that the 5th argument
+# (backup servers) isn't mandatory.
inurl="$3"
outname="$4"
lockfile="$2"
downloader="$1"
+backupservers="$5"
if [ "x$downloader" = x ]; then
echo "$0: downloader (first argument) not given."; exit 1;
fi
@@ -73,6 +75,13 @@ fi
+# Separate the actual filename, to possibly use backup server.
+urlfile=$(echo "$inurl" | awk -F "/" '{print $NF}')
+
+
+
+
+
# Try downloading multiple times before crashing.
counter=0
maxcounter=10
@@ -107,8 +116,19 @@ while [ ! -f "$outname" ]; do
if [ x"$lockfile" = xnolock ]; then
if ! $downloader $outname $inurl; then rm -f $outname; fi
else
+ # Try downloading from the requested URL.
flock "$lockfile" bash -c \
"if ! $downloader $outname $inurl; then rm -f $outname; fi"
+
+ # If it failed, try the backup server(s).
+ if [ ! -f "$outname" ]; then
+ if [ x"$backupservers" != x ]; then
+ for bs in "$backupservers"; do
+ flock "$lockfile" bash -c \
+ "if ! $downloader $outname $bs/$urlfile; then rm -f $outname; fi"
+ done
+ fi
+ fi
fi
done