diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-01 17:52:09 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-01 17:52:09 -0400 |
commit | 7effa83470019f75931296c6a5d07a5932c69df8 (patch) | |
tree | 26795effe5cef5721a9838f016e74207eb751e1b /doc/special_remotes | |
parent | 13dee7b4750bc771ea3747926249f1c47ca54770 (diff) |
fix example external remote script to write files atomically
Diffstat (limited to 'doc/special_remotes')
-rwxr-xr-x | doc/special_remotes/external/example.sh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/doc/special_remotes/external/example.sh b/doc/special_remotes/external/example.sh index 5152ccc28..8fed9f4aa 100755 --- a/doc/special_remotes/external/example.sh +++ b/doc/special_remotes/external/example.sh @@ -128,14 +128,25 @@ while read line; do STORE) # Store the file to a location # based on the key. - # XXX when possible, send PROGRESS + # XXX when at all possible, send PROGRESS calclocation "$key" mkdir -p "$(dirname "$LOC")" - if runcmd cp "$file" "$LOC"; then + # Store in temp file first, so that + # CHECKPRESENT does not see it + # until it is all stored. + mkdir -p "$mydirectory/tmp" + tmp="$mydirectory/tmp/$key" + if runcmd cp "$file" "$tmp" \ + && runcmd mv -f "$tmp" "$LOC"; then echo TRANSFER-SUCCESS STORE "$key" else echo TRANSFER-FAILURE STORE "$key" fi + + mkdir -p "$(dirname "$LOC")" + # The file may already exist, so + # make sure we can overwrite it. + chmod 644 "$LOC" 2>/dev/null || true ;; RETRIEVE) # Retrieve from a location based on |