Skip to content

Commit

Permalink
fix: unpack cache cleanup should ignore missing files (#404)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
  • Loading branch information
joelanford committed Sep 18, 2024
1 parent f0ef22a commit 8c6625f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/source/containers_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ func successResult(catalog *catalogdv1alpha1.ClusterCatalog, unpackPath string,
}

func (i *ContainersImageRegistry) Cleanup(_ context.Context, catalog *catalogdv1alpha1.ClusterCatalog) error {
return deleteRecursive(i.catalogPath(catalog.Name))
if err := deleteRecursive(i.catalogPath(catalog.Name)); err != nil {
return fmt.Errorf("error deleting catalog cache: %w", err)
}
return nil
}

func (i *ContainersImageRegistry) catalogPath(catalogName string) string {
Expand Down Expand Up @@ -380,6 +383,9 @@ func setReadOnlyRecursive(root string) error {

func deleteRecursive(root string) error {
if err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
if os.IsNotExist(err) {
return nil
}
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/source/containers_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ func TestImageRegistry(t *testing.T) {
isUnrecov := errors.As(err, &catalogderrors.Unrecoverable{})
assert.Equal(t, tt.unrecoverable, isUnrecov, "expected unrecoverable %v, got %v", tt.unrecoverable, isUnrecov)
}

assert.NoError(t, imgReg.Cleanup(ctx, tt.catalog))
assert.NoError(t, imgReg.Cleanup(ctx, tt.catalog), "cleanup should ignore missing files")
})
}
}
Expand Down

0 comments on commit 8c6625f

Please sign in to comment.