diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-10-04 04:06:19 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-10-04 04:06:19 -0400 |
commit | b3afdd50c4121a82a8de61dba1a7ad2d0bd8e901 (patch) | |
tree | 0ca2687b7e6408f0d4b0ca39b383c767bd98583d | |
parent | d344c0cb1e940e1d63905b68dcde448235b8185c (diff) |
test: common.bash: common_teardown: Don't assume that common_setup went OK
common_setup might have errored before setting tmpdir or chrootdir; handle
those cases.
-rw-r--r-- | test/lib/common.bash | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/test/lib/common.bash b/test/lib/common.bash index c55ebc5..7663a9b 100644 --- a/test/lib/common.bash +++ b/test/lib/common.bash @@ -60,25 +60,29 @@ common_setup() { common_teardown() { gpg-connect-agent KILLAGENT /bye || true - if [[ -f "$tmpdir/.used-sudo" ]]; then - sudo rm -rf -- "$tmpdir" - else - rm -rf -- "$tmpdir" + if [[ -n ${tmpdir:-} ]]; then + if [[ -f "$tmpdir/.used-sudo" ]]; then + sudo rm -rf -- "$tmpdir" + else + rm -rf -- "$tmpdir" + fi fi # Clean up non-root chroots. On btrfs it wouldn't be terrible # to wait until the end because CoW means that they don't take # up much space, but on other filesystems, we don't want to # require such a large disk. - local dir - for dir in "$chrootdir"/*/*/; do - if [[ -d $dir && $dir != */root/ ]]; then - if [[ "$(stat -f -c %T "$dir")" == btrfs ]]; then - sudo find "$dir" -depth -inum 256 -exec \ - btrfs subvolume delete {} \; &>/dev/null + if [[ -n ${chrootdir:-} ]]; then + local dir + for dir in "$chrootdir"/*/*/; do + if [[ -d $dir && $dir != */root/ ]]; then + if [[ "$(stat -f -c %T "$dir")" == btrfs ]]; then + sudo find "$dir" -depth -inum 256 -exec \ + btrfs subvolume delete {} \; &>/dev/null + fi + sudo rm -rf -- "$dir" fi - sudo rm -rf -- "$dir" - fi - done + done + fi } setup() { |