Implement idempotent cleanup behavior

This commit is contained in:
2026-09-05 15:15:28 +00:00
parent 563acce012
commit 8d9eb5cc40
6 changed files with 420 additions and 1 deletions

View File

@@ -13,6 +13,9 @@ import (
func RemoveAllUnderRoot(rootPath, target string) error {
root, targetName, err := openCleanupRoot(rootPath, target)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}
defer func() { _ = root.Close() }()

View File

@@ -34,6 +34,14 @@ func TestRemoveAllUnderRootRemovesNestedTreeIdempotently(t *testing.T) {
}
}
func TestCleanupRemoveAllUnderRootAcceptsMissingRoot(t *testing.T) {
root := filepath.Join(t.TempDir(), "absent")
target := filepath.Join(root, "runs", "run-1")
if err := RemoveAllUnderRoot(root, target); err != nil {
t.Fatalf("RemoveAllUnderRoot() with missing root error = %v", err)
}
}
func TestRemoveAllUnderRootRejectsUnsafeTargets(t *testing.T) {
root := t.TempDir()
outside := t.TempDir()