aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan S. Arnold <ryan.arnold@linaro.org>2015-05-19 13:58:44 -0500
committerRobert Savoye <rob.savoye@linaro.org>2015-05-20 01:28:55 +0000
commit6b11762fb9bb76c8a0a93f2faf6392c5860def6f (patch)
tree0158b9e83fdfe060e4f795da168fccdad1679ea4
parent670a1a95212da11753cbd3b1f159c15879c3adb8 (diff)
${force} now overwrites existing files in fetch_http()
The wget program will not overwrite a file unless -O is used to specify the output file name on the command line. This patch enables -O ${local_snapshots}/${getfile} to overwrite the existing file if ${force} is specified. It also moves a check for ${force} to the top of the function so that fetch_http() won't return 0 automatically if ${force} is specified but the ${getfile} already exists. This also allows us to squash an if-block around the wget call. A test-case was added to verify that fetch_http works with ${force} = yes. Change-Id: I685011b3383bd0aa7f1cf01a31ca22b77c0c5d41
-rwxr-xr-xlib/fetch.sh43
-rwxr-xr-xtestsuite/test.sh20
2 files changed, 40 insertions, 23 deletions
diff --git a/lib/fetch.sh b/lib/fetch.sh
index c7ef74db..f9ac0fea 100755
--- a/lib/fetch.sh
+++ b/lib/fetch.sh
@@ -135,7 +135,9 @@ fetch_http()
fi
fi
- if test -e ${local_snapshots}/${getfile}; then
+ # If it exists and the caller didn't ask for downloading to be forced then
+ # we don't need to download it again.
+ if test -e ${local_snapshots}/${getfile} -a x"${force}" != xyes; then
notice "${getfile} already exists."
return 0
elif test x"${supdate}" = xno; then
@@ -150,29 +152,26 @@ fetch_http()
return 1
fi
- if test ! -e ${local_snapshots}/${getfile} -o x"${force}" = xyes; then
- # We don't want this message for md5sums, since it's so often
- # downloaded.
- if test x"${getfile}" != x"md5sums"; then
- notice "Downloading ${getfile} to ${local_snapshots}"
- fi
+ # We don't want this message for md5sums, since it's so often
+ # downloaded.
+ if test x"${getfile}" != x"md5sums"; then
+ notice "Downloading ${getfile} to ${local_snapshots}"
+ fi
- # NOTE: the timeout is short, and we only try twice to access the
- # remote host. This is to improve performance when offline, or
- # the remote host is offline.
- dryrun "${wget_bin} ${wget_quiet:+-q} --timeout=${wget_timeout}${wget_progress_style:+ --progress=${wget_progress_style}} --tries=2 --directory-prefix=${local_snapshots}/${dir} http://${fileserver}/${remote_snapshots}/${getfile}"
- ret=$?
- if test x"${dryrun}" != xyes -a ! -s ${local_snapshots}/${getfile}; then
- warning "downloaded file ${getfile} has zero data!"
- return 1
- fi
- else
- # We don't want this message for md5sums, since it's so often
- # downloaded.
- if test x"${getfile}" != x"md5sums"; then
- notice "${getfile} already exists in ${local_snapshots}"
- fi
+ local overwrite=
+ if test x${force} = xyes; then
+ overwrite="-O ${local_snapshots}/${getfile}"
fi
+
+ # NOTE: the timeout is short, and we only try twice to access the
+ # remote host. This is to improve performance when offline, or
+ # the remote host is offline.
+ dryrun "${wget_bin} ${wget_quiet:+-q} --timeout=${wget_timeout}${wget_progress_style:+ --progress=${wget_progress_style}} --tries=2 --directory-prefix=${local_snapshots}/${dir} http://${fileserver}/${remote_snapshots}/${getfile}${overwrite:+ ${overwrite}}"
+ if test x"${dryrun}" != xyes -a ! -s ${local_snapshots}/${getfile}; then
+ warning "downloaded file ${getfile} has zero data!"
+ return 1
+ fi
+
return 0
}
diff --git a/testsuite/test.sh b/testsuite/test.sh
index a3c47bf4..3417ff21 100755
--- a/testsuite/test.sh
+++ b/testsuite/test.sh
@@ -555,7 +555,8 @@ sleep 1s
out="`supdate=yes fetch_http infrastructure/gmp-5.1.3.tar.xz 2>/dev/null`"
ret=$?
-# Compare the second timestamp to make sure they're equal.
+# Compare the second timestamp to make sure they're equal (i.e., that a new
+# one wasn't downloaded).
gmp_stamp2=`stat -c %X ${local_snapshots}/infrastructure/gmp-5.1.3.tar.xz`
if test $ret -eq 0 -a ${gmp_stamp1} -eq ${gmp_stamp2}; then
@@ -564,6 +565,23 @@ else
fail "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=yes"
fi
+# Sleep so that the timestamps differ (if they will)
+sleep 1s
+
+# Try to download it again with supdate=yes and force=yes explicit it
+# should download it again and return 0 (and the timestamp should differ)
+out="`force=yes supdate=yes fetch_http infrastructure/gmp-5.1.3.tar.xz 2>/dev/null`"
+ret=$?
+
+# Compare to the second timestamp to make sure they're not equal.
+gmp_stamp3=`stat -c %X ${local_snapshots}/infrastructure/gmp-5.1.3.tar.xz`
+
+if test $ret -eq 0 -a ${gmp_stamp2} -ne ${gmp_stamp3}; then
+ pass "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=yes and \${force}=yes"
+else
+ fail "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=yes and \${force}=yes"
+fi
+
out="`fetch_http md5sums 2>/dev/null`"
if test $? -eq 0; then
pass "fetch_http md5sums"