fix example external remote script to write files atomically
This commit is contained in:
parent
de0da0aece
commit
50a1cac24f
1 changed files with 13 additions and 2 deletions
15
doc/special_remotes/external/example.sh
vendored
15
doc/special_remotes/external/example.sh
vendored
|
@ -128,14 +128,25 @@ while read line; do
|
||||||
STORE)
|
STORE)
|
||||||
# Store the file to a location
|
# Store the file to a location
|
||||||
# based on the key.
|
# based on the key.
|
||||||
# XXX when possible, send PROGRESS
|
# XXX when at all possible, send PROGRESS
|
||||||
calclocation "$key"
|
calclocation "$key"
|
||||||
mkdir -p "$(dirname "$LOC")"
|
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"
|
echo TRANSFER-SUCCESS STORE "$key"
|
||||||
else
|
else
|
||||||
echo TRANSFER-FAILURE STORE "$key"
|
echo TRANSFER-FAILURE STORE "$key"
|
||||||
fi
|
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)
|
||||||
# Retrieve from a location based on
|
# Retrieve from a location based on
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue