aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan S. Arnold <ryan.arnold@linaro.org>2015-05-19 14:25:56 -0500
committerRyan S. Arnold <ryan.arnold@linaro.org>2015-05-19 14:25:56 -0500
commit0c34d72b5e31b1b49b6605f8d7a50307d3ebb87d (patch)
treeb5701eee8e87bfa8d07b5c478db26e7daa635ec5
parent2bf43860829ce185b4780fa33797150e34138942 (diff)
Improve handling of supdate option as it relates to the md5sums file.
[Linaro Bugzilla 1536] - https://bugs.linaro.org/show_bug.cgi?id=1536 Only move md5sums to md5sums.bak if it actually exists. Don't exit early (with success) from fetch_http() if ${supdate} = no because if fetch_http() is called the first time with supdate=no (user error) the source won't actually exist. Improve upon patch by Rob Savoye by making sure that ${getfile} file exists if ${supdate} = no, otherwise return an error. Add fetch_http() tests to testsuite/test.sh. Change-Id: I9a7989ea42f96662bf2e88d0ae4f7534439030f2
-rwxr-xr-xlib/fetch.sh23
-rwxr-xr-xtestsuite/test.sh51
2 files changed, 64 insertions, 10 deletions
diff --git a/lib/fetch.sh b/lib/fetch.sh
index f424d1f8..201e8733 100755
--- a/lib/fetch.sh
+++ b/lib/fetch.sh
@@ -35,9 +35,10 @@ fetch()
# The md5sums file is a special case as it's used to find all
# the other names of the tarballs for remote downloading.
if test x"$1" = x"md5sums"; then
- # Move the existing file to force a fresh copy to be downloaded.
- # Otherwise this file can get stale, and new tarballs not found.
- if test -f ${local_snapshots}/md5sums; then
+ # Move the existing file to force a fresh copy to be downloaded
+ # every time ABE is run. Otherwise this file can get stale, and new
+ # tarballs will not be found.
+ if test -f ${local_snapshots}/md5sums -a x"${supdate}" = x"yes"; then
mv -f ${local_snapshots}/md5sums ${local_snapshots}/md5sums.bak
fi
fetch_http md5sums
@@ -123,9 +124,6 @@ fetch()
fetch_http()
{
# trace "$*"
- if test x"${supdate}" = xno; then
- return 0
- fi
local getfile=$1
local dir="`dirname $1`/"
@@ -137,16 +135,21 @@ fetch_http()
fi
fi
- if test x"${supdate}" = xno -a -e ${local_snapshots}/${getfile}; then
+ if test -e ${local_snapshots}/${getfile}; then
notice "${getfile} already exists."
return 0
- else
+ elif test x"${supdate}" = xno; then
error "${getfile} doesn't exist and you disabled updating."
- return 0
+ return 1
fi
if test ! -e ${local_snapshots}/${getfile} -o x"${force}" = xyes; then
- notice "Downloading ${getfile} to ${local_snapshots}"
+ # 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
+
if test x"${wget_bin}" != x; then
# --continue --progress=bar
# NOTE: the timeout is short, and we only try twice to access the
diff --git a/testsuite/test.sh b/testsuite/test.sh
index 5e080c18..f007f5eb 100755
--- a/testsuite/test.sh
+++ b/testsuite/test.sh
@@ -525,6 +525,57 @@ else
fi
# ----------------------------------------------------------------------------------
+echo "============= fetch_http() tests ================"
+
+# It doesn't exist yet, so it should error out if we try to fetch with supdate=no.
+out="`supdate=no fetch_http infrastructure/gmp-5.1.3.tar.xz 2>/dev/null`"
+if test $? -gt 0 -a ! -e ${local_snapshots}/infrastructure/gmp-5.1.3.tar.xz; then
+ pass "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=no"
+else
+ fail "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=no"
+fi
+
+# Now try to download it with supdate=yes (default) unspecified and it should
+# work and return 0 and show the file has been downloaded.
+out="`fetch_http infrastructure/gmp-5.1.3.tar.xz 2>/dev/null`"
+if test $? -eq 0 -a -e ${local_snapshots}/infrastructure/gmp-5.1.3.tar.xz; then
+ pass "fetch_http infrastructure/gmp-5.1.3.tar.xz (implicit \${supdate}=yes)"
+else
+ fail "fetch_http infrastructure/gmp-5.1.3.tar.xz (implicit \${supdate}=yes)"
+fi
+
+# Get a timestamp of the first downloaded version.
+gmp_stamp1=`stat -c %X ${local_snapshots}/infrastructure/gmp-5.1.3.tar.xz`
+
+# Sleep so that the timestamps differ (if they will)
+sleep 1s
+
+# Try to download it again with supdate=yes explicit and it
+# should return 0 (that we've already downloaded it) but not download again.
+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.
+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
+ pass "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=yes"
+else
+ fail "fetch_http infrastructure/gmp-5.1.3.tar.xz with \${supdate}=yes"
+fi
+
+out="`fetch_http md5sums 2>/dev/null`"
+if test $? -eq 0; then
+ pass "fetch_http md5sums"
+else
+ fail "fetch_http md5sums"
+fi
+
+# remove md5sums so we can test fetch().
+if test ! -e "${local_snapshots}/md5sums"; then
+ rm ${local_snapshots}/md5sums
+fi
+
echo "============= fetch() tests ================"
out="`fetch md5sums 2>/dev/null`"
if test $? -eq 0; then