From 3dd8920d9f8ca9b868f01fb136e9eb5d3bade338 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Fri, 14 Dec 2012 16:04:02 -0600 Subject: 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 --- bin/ftpsync | 11 ++++++----- 1 file 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 ;; *) -- cgit v1.2.3