Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 unpack cache cleanup should ignore missing files #404

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines +177 to +179
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now at least, deleteRecursive already has a wrapper text:

error making catalog cache writable for deletion:.

Do we need this?

Alternatively, if we want the nice to have error deleting catalog cache: error making catalog cache writable for deletion:.. wrappers, the next line should return nil (it's recalling deleteRecursive again)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the below line needing a change.

I'm not strongly opinionated on the wrapping, but generally I always try to add more context where possible to help with "tracing" the actions taken from error logs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is leftover from me manually testing idempotence. I'll remove.

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")
joelanford marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand Down