+ "$@" "$target_tmp" \
+|| {
+ # Try to remove the target directory without changing the exit code. In
+ # case the connection failed without transferring any files, we want to
+ # remove the empty directory.
+ code=$?
+ rmdir "$target_tmp" 2>/dev/null || true
+ exit $code
+}
+mv "$target_tmp" "$target"