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

Fixes to storage’s GetBlob #2394

Merged
merged 2 commits into from
May 16, 2024
Merged

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented May 3, 2024

… tangentially related to containers/podman#22575 :

  • Go is a treacherously innocuous-looking language. Get rid of unnecessary named return values
  • Fix removal of the layer temporary file.

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

Thanks, because I got tripped by these while reading the code in the context of containers/podman#22575

@@ -107,12 +107,11 @@ func (s *storageImageSource) Close() error {
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
func (s *storageImageSource) GetBlob(ctx context.Context, info types.BlobInfo, cache types.BlobInfoCache) (rc io.ReadCloser, n int64, err error) {
func (s *storageImageSource) GetBlob(ctx context.Context, info types.BlobInfo, cache types.BlobInfoCache) (io.ReadCloser, int64, error) {
Copy link
Member

Choose a reason for hiding this comment

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

A combination of several deferred calls, and a return value that's a direct function call, which itself takes an unnamed function, makes these named return values treacherously confusing. :)

@@ -177,7 +176,7 @@ func (s *storageImageSource) GetBlob(ctx context.Context, info types.BlobInfo, c
// On Unix and modern Windows (2022 at least) we can eagerly unlink the file to ensure it's automatically
// cleaned up on process termination (or if the caller forgets to invoke Close())
// On older versions of Windows we will have to fallback to relying on the caller to invoke Close()
if err := os.Remove(tmpFile.Name()); err != nil {
if err := os.Remove(tmpFile.Name()); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

I had found myself scratching my head over this logic too but had set it aside because it didn't seem directly relevant to the issue at hand.

@mtrmac mtrmac force-pushed the storage-GetBlob branch 2 times, most recently from 6883af1 to a37e4f7 Compare May 9, 2024 19:36
@mtrmac mtrmac added the kind/bug A defect in an existing functionality (or a PR fixing it) label May 13, 2024
@rhatdan
Copy link
Member

rhatdan commented May 13, 2024

LGTM

They get horribly confusing, especially here where we use "rc"
for two completely different purposes:
containers/podman#22575 (comment)

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Try unlinking it when we are done using if we
_don't_ succeed unlinking it first, not if we _do succeed_.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@rhatdan
Copy link
Member

rhatdan commented May 14, 2024

@giuseppe @mheon @debarshiray PTAL

@mheon
Copy link
Member

mheon commented May 14, 2024

LGTM

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

@debarshiray
Copy link
Member

@giuseppe @mheon @debarshiray PTAL

I already did. I couldn't spot any further changes after the initial version. :)

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@giuseppe giuseppe merged commit 5e7756c into containers:main May 16, 2024
10 checks passed
@mtrmac mtrmac deleted the storage-GetBlob branch May 16, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira kind/bug A defect in an existing functionality (or a PR fixing it)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants