diff --git a/.changelog/23237.txt b/.changelog/23237.txt new file mode 100644 index 000000000..20649614f --- /dev/null +++ b/.changelog/23237.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Fixed a bug where empty task directories would be left behind +``` diff --git a/client/allocdir/task_dir.go b/client/allocdir/task_dir.go index 2d2fca001..14146552f 100644 --- a/client/allocdir/task_dir.go +++ b/client/allocdir/task_dir.go @@ -349,6 +349,14 @@ func (t *TaskDir) Unmount() error { } } + // delete the task's parent alloc mounts dir if it exists + if dir := filepath.Dir(t.MountsAllocDir); pathExists(dir) { + if err := os.RemoveAll(dir); err != nil { + mErr.Errors = append(mErr.Errors, + fmt.Errorf("failed to remove the task alloc mounts dir %q: %w", dir, err)) + } + } + if pathExists(t.SecretsDir) { if err := removeSecretDir(t.SecretsDir); err != nil { mErr = multierror.Append(mErr,