+ "$@" "$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
+}
+# --dry-run (-n) creates an empty directory. Remove it to prevent using it for
+# further incremental backups (which would do a full backup).
+rmdir "$target_tmp" 2>/dev/null && exit 0 || true
+
+mv "$target_tmp" "$target"