bkctld-rm: delete empty jails in incs directory
This commit is contained in:
parent
f9018738b9
commit
76a298c042
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
* bkctld: add a [-f|--force] option to remove confirmation on some commands
|
||||
* bkctld-remove: confirmation before removal of jails if not in force mode
|
||||
* bkctld-rm: delete empty jails in incs directory
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -84,6 +84,21 @@ delete_inc_ext4() {
|
|||
fi
|
||||
|
||||
}
|
||||
delete_empty_inc() {
|
||||
jail_name=$1
|
||||
|
||||
incs_path=$(incs_path "${jail_name}")
|
||||
empty_incs_list=$(find "${incs_path}" -mindepth 0 -maxdepth 0 -type d -empty)
|
||||
|
||||
for empty_inc in ${empty_incs_list}; do
|
||||
if dry_run; then
|
||||
echo "[dry-run] Delete empty \`${empty_inc}'"
|
||||
else
|
||||
rmdir "${empty_inc}"
|
||||
notice "Delete empty \`${empty_inc}' : OK"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
lock_file="${LOCKDIR}/rm-global.lock"
|
||||
# shellcheck disable=SC2064
|
||||
|
@ -104,7 +119,6 @@ for jail_name in ${jails_list}; do
|
|||
# If no incs policy is found, we don't remove incs
|
||||
if [ -n "${incs_policy_file}" ]; then
|
||||
# shellcheck disable=SC2046
|
||||
|
||||
incs_to_delete=$(incs_to_delete "${jail_name}" "${incs_policy_file}")
|
||||
incs_total=$(echo ${incs_to_delete} | wc -w)
|
||||
incs_count=0
|
||||
|
@ -132,6 +146,8 @@ for jail_name in ${jails_list}; do
|
|||
else
|
||||
notice "Skip jail \`${jail_name}' : incs policy is missing"
|
||||
fi
|
||||
# Delete empty incs directory for jail
|
||||
delete_empty_inc "${jail_name}"
|
||||
done
|
||||
|
||||
# Remove the lock file and cleanup tmp files
|
||||
|
|
|
@ -184,6 +184,10 @@ incs_list() {
|
|||
jail_name=${1:?}
|
||||
find "$(incs_path "${jail_name}")" -mindepth 1 -maxdepth 1 -type d | sed 's!.*/!!' | sort -h
|
||||
}
|
||||
# Return the list of empty incs directories
|
||||
empty_incs_list() {
|
||||
find ${INCDIR} -mindepth 1 -maxdepth 1 -type d -empty
|
||||
}
|
||||
current_jail_incs_policy_file() {
|
||||
jail_name=${1:?}
|
||||
|
||||
|
|
|
@ -87,4 +87,21 @@ load test_helper
|
|||
assert_failure
|
||||
}
|
||||
|
||||
@test "empty inc directory are removed" {
|
||||
# Create an inc
|
||||
/usr/lib/bkctld/bkctld-inc
|
||||
# no inc should be kept
|
||||
echo '' > "${CONFDIR}/${JAILNAME}.d/incs_policy"
|
||||
|
||||
# The inc directory is present
|
||||
run test -d "${INCSPATH}"
|
||||
assert_success
|
||||
|
||||
/usr/lib/bkctld/bkctld-rm
|
||||
|
||||
# The inc directory is absent
|
||||
run test -d "${INCSPATH}"
|
||||
assert_failure
|
||||
}
|
||||
|
||||
# TODO: add many tests for incs (creation and removal)
|
||||
|
|
Loading…
Reference in a new issue