Backout on box creation if image is in use.

This commit is contained in:
Jakob Aarøe Dam
2015-04-17 16:13:21 +02:00
parent c80841943c
commit 7782113fae

View File

@@ -3,7 +3,7 @@
error() { error() {
local msg="${1}" local msg="${1}"
echo "==> ${msg}" echo "==> ERROR: ${msg}"
exit 1 exit 1
} }
@@ -70,6 +70,10 @@ if [[ -n $(backing "$IMG") ]]; then
cp "$IMG" "$TMP_IMG" cp "$IMG" "$TMP_IMG"
rebase "$TMP_IMG" rebase "$TMP_IMG"
else else
if fuser -s "$IMG"; then
error "Image '$IMG_BASENAME' is used by another process"
fi
# move the image to get a speed-up and use less space on disk # move the image to get a speed-up and use less space on disk
trap 'mv "$TMP_IMG" "$IMG"; rm -rf "$TMP_DIR"' EXIT trap 'mv "$TMP_IMG" "$IMG"; rm -rf "$TMP_DIR"' EXIT
mv "$IMG" "$TMP_IMG" mv "$IMG" "$TMP_IMG"