summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Geissert <geissert@debian.org>2012-12-14 16:04:02 -0600
committerSimon Paillard <spaillard@debian.org>2013-05-01 01:23:16 +0200
commit3dd8920d9f8ca9b868f01fb136e9eb5d3bade338 (patch)
treeedc08bc458945c746e61243afe77a0b6637fccfd
parente1e7735ca02767d458b7b3cafae76c6dd844fc94 (diff)
Replace the trace file atomically
Given the additional calls that append to the trace file, it could be possible for an incomplete file to be downloaded, leading to unexpected results. Signed-off-by: Raphael Geissert <geissert@debian.org>
-rwxr-xr-xbin/ftpsync11
1 files changed, 6 insertions, 5 deletions
diff --git a/bin/ftpsync b/bin/ftpsync
index e513b95..da665e5 100755
--- a/bin/ftpsync
+++ b/bin/ftpsync
@@ -549,9 +549,9 @@ if [ "xtruex" = "x${SYNCSTAGE2}x" ] || [ "xtruex" = "x${SYNCALL}x" ]; then
terse|full)
log "Creating a ${EXTENDEDTRACE} trace file"
if [ -d "$(dirname "${TO}/${TRACE}")" ]; then
- LC_ALL=POSIX LANG=POSIX date -u > "${TO}/${TRACE}"
- echo "Used ftpsync version: ${VERSION}" >> "${TO}/${TRACE}"
- echo "Running on host: $(hostname -f)" >> "${TO}/${TRACE}"
+ LC_ALL=POSIX LANG=POSIX date -u > "${TO}/${TRACE}.new"
+ echo "Used ftpsync version: ${VERSION}" >> "${TO}/${TRACE}.new"
+ echo "Running on host: $(hostname -f)" >> "${TO}/${TRACE}.new"
if [ "xfullx" = "x${EXTENDEDTRACE}x" ]; then
GLOBALARCHLIST="source amd64 armel armhf hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc"
@@ -563,9 +563,10 @@ if [ "xtruex" = "x${SYNCSTAGE2}x" ] || [ "xtruex" = "x${SYNCALL}x" ]; then
fi
done
out="GUESSED:{${ARCHLIST}}"
- echo "Architectures: ${out}" >> "${TO}/${TRACE}"
- echo "Upstream-mirror: ${RSYNC_HOST}" >> "${TO}/${TRACE}"
+ echo "Architectures: ${out}" >> "${TO}/${TRACE}.new"
+ echo "Upstream-mirror: ${RSYNC_HOST}" >> "${TO}/${TRACE}.new"
fi # full trace
+ mv "${TO}/${TRACE}.new" "${TO}/${TRACE}"
fi
;;
*)