summaryrefslogtreecommitdiffstats
path: root/support/download/bzr
diff options
context:
space:
mode:
Diffstat (limited to 'support/download/bzr')
-rwxr-xr-xsupport/download/bzr25
1 files changed, 22 insertions, 3 deletions
diff --git a/support/download/bzr b/support/download/bzr
index f07732e7e0..3f52ee9eb7 100755
--- a/support/download/bzr
+++ b/support/download/bzr
@@ -9,11 +9,30 @@ set -e
# $2: bzr revision
# $3: output file
# And this environment:
-# BZR : the bzr command to call
-# BR2_DL_DIR: path to Buildroot's download dir
+# BZR : the bzr command to call
+# BUILD_DIR: path to Buildroot's build dir
repo="${1}"
rev="${2}"
output="${3}"
-${BZR} export "${output}" "${repo}" -r "${rev}"
+tmp_dl="$( mktemp "${BUILD_DIR}/.XXXXXX" )"
+tmp_output="$( mktemp "${output}.XXXXXX" )"
+
+# Play tic-tac-toe with temp files
+# - first, we download to a trashable location (the build-dir)
+# - the we move to a temp file in the final location, so it is
+# on the same filesystem as the final file
+# - finally, we atomically rename to the final file
+
+ret=1
+if ${BZR} export "${tmp_dl}" "${repo}" -r "${rev}"; then
+ if mv "${tmp_dl}" "${tmp_output}"; then
+ mv "${tmp_output}" "${output}"
+ ret=0
+ fi
+fi
+
+# Cleanup
+rm -f "${tmp_dl}" "${tmp_output}"
+exit ${ret}
OpenPOWER on IntegriCloud