1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #1174: check that the SOURCE attribute is properly set before executing oneimage delete

(cherry picked from commit 83e9146a4958c94cbc464ff8889be58aad8c69d5)
This commit is contained in:
Jaime Melis 2012-04-04 09:41:50 +02:00
parent 22d29acc9a
commit a4880ecabf
3 changed files with 42 additions and 6 deletions

View File

@ -39,12 +39,26 @@ DRV_ACTION=$1
ID=$2
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE`
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
/DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH)
SRC="${XPATH_ELEMENTS[0]}"
BASE_PATH="${XPATH_ELEMENTS[1]}"
# ------------ Remove the image from the repository ------------
if [ -e $SRC ] ; then
if [ -f "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n `basename "$SRC"` ]
then
log "Removing $SRC from the image repository"
exec_and_log "rm -r $SRC" \
exec_and_log "rm -f $SRC" \
"Error deleting $SRC"
else
log_error "Bad formed or unavailable Image source: ${SRC}"
exit 1
fi

View File

@ -72,7 +72,15 @@ function generate_image_path {
$CANONICAL_STR
EOF
)
echo "${BASE_PATH}/`echo $CANONICAL_MD5 | cut -d ' ' -f1`"
IMAGE_HASH=$(echo $CANONICAL_MD5 | cut -d ' ' -f1)
IMAGE_HASH=$(basename "$IMAGE_HASH")
if [ -z "$IMAGE_HASH" ]; then
log_error "Error generating the path in generate_image_path."
exit 1
fi
echo "${BASE_PATH}/${IMAGE_HASH}"
}
#-------------------------------------------------------------------------------

View File

@ -39,12 +39,26 @@ DRV_ACTION=$1
ID=$2
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE`
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
/DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH)
SRC="${XPATH_ELEMENTS[0]}"
BASE_PATH="${XPATH_ELEMENTS[1]}"
# ------------ Remove the image from the repository ------------
if [ -e $SRC ] ; then
if [ -d "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n `basename "$SRC"` ]
then
log "Removing $SRC from the image repository"
exec_and_log "rm -r $SRC" \
"Error deleting $SRC"
else
log_error "Bad formed or unavailable Image source: ${SRC}"
exit 1
fi