__file: make the create-empty-file case work again

Signed-off-by: Steven Armstrong <steven@armstrong.cc>
This commit is contained in:
Steven Armstrong 2022-04-14 00:46:13 +02:00
parent 2df2578e36
commit 8b915b15b5

View file

@ -72,6 +72,7 @@ if [ "$state_should" = "present" ] || [ "$state_should" = "exists" ]; then
if [ "$type" != "file" ]; then if [ "$type" != "file" ]; then
# destination is not a regular file, upload source to replace it # destination is not a regular file, upload source to replace it
upload_file=1 upload_file=1
echo upload >> "$__messages_out"
else else
local_cksum="$(cksum < "$source")" local_cksum="$(cksum < "$source")"
remote_cksum="$(cat "$__object/explorer/cksum")" remote_cksum="$(cat "$__object/explorer/cksum")"
@ -88,6 +89,14 @@ if [ "$state_should" = "present" ] || [ "$state_should" = "exists" ]; then
mkdir "$__object/files" mkdir "$__object/files"
touch "$__object/files/set-attributes" touch "$__object/files/set-attributes"
if [ "$create_file" ]; then
# When creating an empty file we create it locally and then
# upload it so that permissions can be set before moving the file
# into place.
source="$__object/files/empty"
touch "$source"
fi
# upload file to temp location # upload file to temp location
upload_destination="$(mktemp -u "/__cdist${destination}.cdist.XXXXXXXXXX" | sed 's|^/__cdist||')" upload_destination="$(mktemp -u "/__cdist${destination}.cdist.XXXXXXXXXX" | sed 's|^/__cdist||')"
# Yes, we are aware that this is a race condition. # Yes, we are aware that this is a race condition.
@ -104,18 +113,15 @@ if [ "$state_should" = "present" ] || [ "$state_should" = "exists" ]; then
# it to its final destination. # it to its final destination.
echo "$upload_destination" > "$__object/files/upload-destination" echo "$upload_destination" > "$__object/files/upload-destination"
if [ "$upload_file" ]; then # IPv6 fix
echo upload >> "$__messages_out" if echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$'
# IPv6 fix then
if echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$' my_target_host="[${__target_host}]"
then else
my_target_host="[${__target_host}]" my_target_host="${__target_host}"
else fi
my_target_host="${__target_host}" cat << DONE
fi
cat << DONE
$__remote_copy "$source" "${my_target_host}:${upload_destination}" $__remote_copy "$source" "${my_target_host}:${upload_destination}"
DONE DONE
fi
fi fi
fi fi