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<image_msg_t> msg)
         goto error;
     }
 
+    image->set_source(source);
+
     is >> format;
 
     if (is.fail() || format.empty())
@@ -111,8 +113,6 @@ void ImageManager::_cp(unique_ptr<image_msg_t> msg)
         goto error_common;
     }
 
-    image->set_source(source);
-
     image->set_format(format);
 
     image->set_state_unlock();