From f59f1b4cf1bbc7c746b6fe264675a681507dc543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Wed, 29 Jun 2022 11:59:24 +0200 Subject: [PATCH] M #-: Cleanup files if unknown format for qemu cp (#2199) (cherry picked from commit f01b28e763ea94e7b3fb4cc44e350b340c996842) --- src/datastore_mad/remotes/fs/cp | 6 ++++++ src/datastore_mad/remotes/fs/rm | 2 +- src/image/ImageManagerProtocol.cc | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/datastore_mad/remotes/fs/cp b/src/datastore_mad/remotes/fs/cp index a97cd5c345..f0cf44c308 100755 --- a/src/datastore_mad/remotes/fs/cp +++ b/src/datastore_mad/remotes/fs/cp @@ -175,6 +175,12 @@ else fi FORMAT=$($QEMU_IMG info $DST | grep "^file format:" | awk '{print $3}' || :) + + if [ -z $FORMAT ]; then + rm -rf $DST + log_error "Unknown image format src=$SRC" + exit -1 + fi fi [[ "$FORMAT" = "luks" ]] && FORMAT="raw" diff --git a/src/datastore_mad/remotes/fs/rm b/src/datastore_mad/remotes/fs/rm index 0050e399ef..f01fb3ed9b 100755 --- a/src/datastore_mad/remotes/fs/rm +++ b/src/datastore_mad/remotes/fs/rm @@ -63,7 +63,7 @@ if [ -n "$BRIDGE_LIST" ]; then "Error deleting $SRC in $DST_HOST" else BASENAME_SRC=`basename "${SRC##$REMOTE_RM_CMD}"` - if [ -f "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n "$BASENAME_SRC" ] + if [ -e "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n "$BASENAME_SRC" ] then log "Removing $SRC from the image repository" diff --git a/src/image/ImageManagerProtocol.cc b/src/image/ImageManagerProtocol.cc index 9fbf32f91c..0d2c7ca89e 100644 --- a/src/image/ImageManagerProtocol.cc +++ b/src/image/ImageManagerProtocol.cc @@ -103,6 +103,8 @@ void ImageManager::_cp(unique_ptr msg) goto error; } + image->set_source(source); + is >> format; if (is.fail() || format.empty()) @@ -111,8 +113,6 @@ void ImageManager::_cp(unique_ptr msg) goto error_common; } - image->set_source(source); - image->set_format(format); image->set_state_unlock();