summaryrefslogtreecommitdiff
path: root/scripts/functions
diff options
context:
space:
mode:
authorYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2010-11-28 23:26:39 (GMT)
committerYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2010-11-28 23:26:39 (GMT)
commit28c5ee8baf8383a991199dc0a2d9734fccd14aba (patch)
treeeaceb4fc98cb6de7a4d14d595c4b2772f84928b2 /scripts/functions
parentaf6dd3f3f0a81a39ed9bb595f70127845de5e3f6 (diff)
scripts: recover on partially downloaded files
Download to an intermediate temp file, and rename it to its final name only of download succeeds. This catches both a failed download, and also the case where the user interrupts the download. Thus, the a partial download gets discarded, and we no longer try to extract a partial tarball, which we would previously have done. Suggested by Thomas PETAZZONI. Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Diffstat (limited to 'scripts/functions')
-rw-r--r--scripts/functions21
1 files changed, 16 insertions, 5 deletions
diff --git a/scripts/functions b/scripts/functions
index e82a832..0bc16f7 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -359,6 +359,8 @@ CT_GetFileExtension() {
# to find the requested URL (think about snapshots, different layouts
# for different gcc versions, etc...).
CT_DoGetFile() {
+ local dest="${1##*/}"
+ local tmp="${dest}.tmp-dl"
# OK, just look if we have them...
# We are sure at least one is available, ./configure checked for it.
local _curl=$(CT_Which curl)
@@ -366,6 +368,9 @@ CT_DoGetFile() {
_curl="${_curl:-false}"
_wget="${_wget:-false}"
+ # Remove potential left-over from a previous run
+ rm -f "${tmp}"
+
# Some (very old!) FTP server might not support the passive mode, thus
# retry without.
# We also retry a few times, in case there is a transient error (eg. behind
@@ -377,11 +382,17 @@ CT_DoGetFile() {
# not easy to detect them, and wget does not timeout by default while
# connecting, so force a global ${CT_CONNECT_TIMEOUT}-second timeout.
# For curl, no good progress indicator is available. So, be silent.
- CT_DoExecLog ALL "${_curl}" --ftp-pasv --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -O "$1" \
- || CT_DoExecLog ALL "${_curl}" --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -O "$1" \
- || CT_DoExecLog ALL "${_wget}" --passive-ftp --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary "$1" \
- || CT_DoExecLog ALL "${_wget}" --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary "$1" \
- || rm -f "${1##*/}"
+ if CT_DoExecLog ALL "${_curl}" --ftp-pasv --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -o "${tmp}" "$1" \
+ || CT_DoExecLog ALL "${_curl}" --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -o "${tmp}" "$1" \
+ || CT_DoExecLog ALL "${_wget}" --passive-ftp --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary -O "${tmp}" "$1" \
+ || CT_DoExecLog ALL "${_wget}" --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary -O "${tmp}" "$1" \
+ ; then
+ # One of them succeeded, good!
+ mv "${tmp}" "${dest}"
+ else
+ # Woops...
+ rm -f "${tmp}"
+ fi
}
# This function tries to retrieve a tarball form a local directory