Skip to content

Fixes to storage’s GetBlob#2394

Merged
giuseppe merged 2 commits intocontainers:mainfrom
mtrmac:storage-GetBlob
May 16, 2024
Merged

Fixes to storage’s GetBlob#2394
giuseppe merged 2 commits intocontainers:mainfrom
mtrmac:storage-GetBlob

Conversation

@mtrmac
Copy link
Copy Markdown
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
Copy Markdown
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

// 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
Copy Markdown
Member

@debarshiray debarshiray May 3, 2024

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. :)

// 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
Copy Markdown
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
Copy Markdown
Member

rhatdan commented May 13, 2024

LGTM

@mtrmac mtrmac force-pushed the storage-GetBlob branch from a37e4f7 to 803e96a Compare May 13, 2024 22:59
mtrmac added 2 commits May 14, 2024 13:29
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>
@mtrmac mtrmac force-pushed the storage-GetBlob branch from 803e96a to 264f4c0 Compare May 14, 2024 11:32
@mtrmac mtrmac added the jira label May 14, 2024
@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented May 14, 2024

@giuseppe @mheon @debarshiray PTAL

@mheon
Copy link
Copy Markdown
Member

mheon commented May 14, 2024

LGTM

Copy link
Copy Markdown
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
Copy Markdown
Member

@giuseppe @mheon @debarshiray PTAL

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

Copy link
Copy Markdown
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
@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.

5 participants