Skip to content

Commit

Permalink
proxy: Make OpenImageOptional work with oci-archive:
Browse files Browse the repository at this point in the history
By adding the standard ENOENT to our list of errors.

I hit this while working on
coreos/rpm-ostree#4598
which is a tool that builds base images and wants to query
if the image exists beforehand.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Sep 15, 2023
1 parent 7c7e600 commit b80b222
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
12 changes: 11 additions & 1 deletion cmd/skopeo/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (

"github.com/containers/image/v5/image"
"github.com/containers/image/v5/manifest"
ociarchive "github.com/containers/image/v5/oci/archive"
ocilayout "github.com/containers/image/v5/oci/layout"
"github.com/containers/image/v5/pkg/blobinfocache"
"github.com/containers/image/v5/transports"
Expand Down Expand Up @@ -229,13 +230,22 @@ func isDockerManifestUnknownError(err error) bool {
return ec.ErrorCode() == dockerdistributionapi.ErrorCodeManifestUnknown
}

func isOciImageNotFound(err error) bool {
var lerr ocilayout.ImageNotFoundError
if errors.As(err, &lerr) {
return true
}
var aerr ociarchive.ImageNotFoundError
return errors.As(err, &aerr)
}

// isNotFoundImageError heuristically attempts to determine whether an error
// is saying the remote source couldn't find the image (as opposed to an
// authentication error, an I/O error etc.)
// TODO drive this into containers/image properly
func isNotFoundImageError(err error) bool {
return isDockerManifestUnknownError(err) ||
errors.Is(err, ocilayout.ImageNotFoundError{})
isOciImageNotFound(err)
}

func (h *proxyHandler) openImageImpl(args []any, allowNotFound bool) (retReplyBuf replyBuf, retErr error) {
Expand Down
19 changes: 19 additions & 0 deletions integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ func runTestOpenImageOptionalNotFound(p *proxy, img string) error {
return nil
}

// Verify that we do see an error if the parent directory doesn't exist
func runTestOpenImageOptionalNoParentDirectory(p *proxy) error {
_, err := p.callNoFd("OpenImageOptional", []any{"oci-archive:/no/such/parent/directory/foo.ociarchive"})
if err == nil {
return fmt.Errorf("Successfully opened nonexistent parent directory")
}
return nil
}

func (s *proxySuite) TestProxy() {
t := s.T()
p, err := newProxy()
Expand All @@ -354,4 +363,14 @@ func (s *proxySuite) TestProxy() {
err = fmt.Errorf("Testing optional image %s: %v", knownNotExtantImage, err)
}
assert.NoError(t, err)

nonExistentArchive := "oci-archive:/enoent"
err = runTestOpenImageOptionalNotFound(p, nonExistentArchive)
if err != nil {
err = fmt.Errorf("Testing optional image %s: %v", nonExistentArchive, err)
}
assert.NoError(t, err)

err = runTestOpenImageOptionalNoParentDirectory(p)
assert.NoError(t, err)
}
19 changes: 13 additions & 6 deletions vendor/github.com/containers/image/v5/oci/archive/oci_transport.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b80b222

Please sign in to comment.