Implement idempotent cleanup behavior
This commit is contained in:
@@ -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() }()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user