summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2017-07-01 07:11:16 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2017-07-01 07:14:21 +0000
commitf910d56dca5abf14c5679eec32ff7d3d57892437 (patch)
treefafd6c9f2a1313bf67b11b5bae5d6a065e910517
parentCorrecting boolean typo when checking for existence of new container in conta... (diff)
downloadcompute-tools-f910d56dca5abf14c5679eec32ff7d3d57892437.tar.xz
compute-tools-f910d56dca5abf14c5679eec32ff7d3d57892437.zip
Avoid removing top-level directories when cleaning up bind mounts in container remove and stop commands.
Previously when using 'bind=/mnt/foo:/foo/bar/baz;', this removed /mnt on the host system too (if empty). Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-xlib/container/remove25
-rwxr-xr-xlib/container/stop30
2 files changed, 47 insertions, 8 deletions
diff --git a/lib/container/remove b/lib/container/remove
index 1b1ba7d..c9a45a6 100755
--- a/lib/container/remove
+++ b/lib/container/remove
@@ -76,6 +76,27 @@ Usage ()
exit 1
}
+Rmdir ()
+{
+ DIRECTORIES="${@}"
+
+ for DIRECTORY in ${DIRECTORIES}
+ do
+ PARENT_DIRECTORY="/$(echo ${DIRECTORY} | cut -d / -f 2)"
+
+ if [ "${PARENT_DIRECTORY}" != "${DIRECTORY}" ]
+ then
+ # the directory is at least two levels down from /
+ cd "${PARENT_DIRECTORY}"
+
+ CRUFT="$(echo ${DIRECTORY} | cut -d / -f 3-)"
+ rmdir --ignore-fail-on-non-empty --parents "${CRUFT}" > /dev/null 2>&1 || true
+
+ cd "${OLDPWD}"
+ fi
+ done
+}
+
Parameters "${@}"
if [ -z "${NAME}" ]
@@ -152,7 +173,7 @@ then
do
DIRECTORY="$(echo ${BIND} | awk -F: '{ print $1 }')"
- rmdir --ignore-fail-on-non-empty --parents ${DIRECTORY} > /dev/null 2>&1 || true
+ Rmdir "${DIRECTORY}"
done
fi
@@ -167,7 +188,7 @@ then
do
DIRECTORY="$(echo ${BIND_RO} | awk -F: '{ print $1 }')"
- rmdir --ignore-fail-on-non-empty --parents ${DIRECTORY} > /dev/null 2>&1 || true
+ Rmdir "${DIRECTORY}"
done
fi
fi
diff --git a/lib/container/stop b/lib/container/stop
index 359a136..12cf7fa 100755
--- a/lib/container/stop
+++ b/lib/container/stop
@@ -78,6 +78,27 @@ Usage ()
exit 1
}
+Rmdir ()
+{
+ DIRECTORIES="${@}"
+
+ for DIRECTORY in ${DIRECTORIES}
+ do
+ PARENT_DIRECTORY="/$(echo ${DIRECTORY} | cut -d / -f 2)"
+
+ if [ "${PARENT_DIRECTORY}" != "${DIRECTORY}" ]
+ then
+ # the directory is at least two levels down from /
+ cd "${PARENT_DIRECTORY}"
+
+ CRUFT="$(echo ${DIRECTORY} | cut -d / -f 3-)"
+ rmdir --ignore-fail-on-non-empty --parents "${CRUFT}" > /dev/null 2>&1 || true
+
+ cd "${OLDPWD}"
+ fi
+ done
+}
+
Parameters "${@}"
if [ -z "${NAME}" ]
@@ -120,10 +141,7 @@ case "${CLEAN}" in
umount -f "${DIRECTORY_MERGED}"
- for DIRECTORY in "${DIRECTORY_LOWER}" "${DIRECTORY_UPPER}" "${DIRECTORY_WORK}" "${DIRECTORY_MERGED}"
- do
- rmdir --ignore-fail-on-non-empty --parents ${DIRECTORY} > /dev/null 2>&1 || true
- done
+ Rmdir "${DIRECTORY_LOWER}" "${DIRECTORY_UPPER}" "${DIRECTORY_WORK}" "${DIRECTORY_MERGED}"
done
fi
@@ -138,7 +156,7 @@ case "${CLEAN}" in
do
DIRECTORY="$(echo ${BIND} | awk -F: '{ print $1 }')"
- rmdir --ignore-fail-on-non-empty --parents ${DIRECTORY} > /dev/null 2>&1 || true
+ Rmdir "${DIRECTORY}"
done
fi
@@ -153,7 +171,7 @@ case "${CLEAN}" in
do
DIRECTORY="$(echo ${BIND_RO} | awk -F: '{ print $1 }')"
- rmdir --ignore-fail-on-non-empty --parents ${DIRECTORY} > /dev/null 2>&1 || true
+ Rmdir "${DIRECTORY}"
done
fi