Skip to content

Fix content.ReaderAt close#5468

Merged
estesp merged 1 commit intocontainerd:masterfrom
wzshiming:fix/close-file
May 10, 2021
Merged

Fix content.ReaderAt close#5468
estesp merged 1 commit intocontainerd:masterfrom
wzshiming:fix/close-file

Conversation

@wzshiming
Copy link
Copy Markdown
Contributor

content.ReaderAt is used in many places but not closed, It will actually call os.Open, this PR complements this close.

// ReaderAt returns an io.ReaderAt for the blob.
func (s *store) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
p, err := s.blobPath(desc.Digest)
if err != nil {
return nil, errors.Wrapf(err, "calculating blob path for ReaderAt")
}
reader, err := OpenReader(p)
if err != nil {
return nil, errors.Wrapf(err, "blob %s expected at %s", desc.Digest, p)
}
return reader, nil
}

// OpenReader creates ReaderAt from a file
func OpenReader(p string) (content.ReaderAt, error) {
fi, err := os.Stat(p)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
return nil, errors.Wrap(errdefs.ErrNotFound, "blob not found")
}
fp, err := os.Open(p)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
return nil, errors.Wrap(errdefs.ErrNotFound, "blob not found")
}
return sizeReaderAt{size: fi.Size(), fp: fp}, nil
}

Signed-off-by: Shiming Zhang <[email protected]>
@k8s-ci-robot
Copy link
Copy Markdown

Hi @wzshiming. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented May 8, 2021

Build succeeded.

Copy link
Copy Markdown
Member

@dmcgowan dmcgowan left a comment

Choose a reason for hiding this comment

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

LGTM

@dmcgowan
Copy link
Copy Markdown
Member

dmcgowan commented May 8, 2021

It will actually call os.Open, this PR complements this close.

When local is used by the client. There are more use cases I have seen that are trying to use the containerd client directly with a content store. When used through the content service, such as the client, the Close doesn't do anything since the content service automatically closes at the end of a request.

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@estesp estesp merged commit 1987f0a into containerd:master May 10, 2021
@wzshiming wzshiming deleted the fix/close-file branch May 12, 2021 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants