Skip to content

Commit b80b222

Browse files
committed
proxy: Make OpenImageOptional work with oci-archive:
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]>
1 parent 7c7e600 commit b80b222

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

cmd/skopeo/proxy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import (
7373

7474
"github.com/containers/image/v5/image"
7575
"github.com/containers/image/v5/manifest"
76+
ociarchive "github.com/containers/image/v5/oci/archive"
7677
ocilayout "github.com/containers/image/v5/oci/layout"
7778
"github.com/containers/image/v5/pkg/blobinfocache"
7879
"github.com/containers/image/v5/transports"
@@ -229,13 +230,22 @@ func isDockerManifestUnknownError(err error) bool {
229230
return ec.ErrorCode() == dockerdistributionapi.ErrorCodeManifestUnknown
230231
}
231232

233+
func isOciImageNotFound(err error) bool {
234+
var lerr ocilayout.ImageNotFoundError
235+
if errors.As(err, &lerr) {
236+
return true
237+
}
238+
var aerr ociarchive.ImageNotFoundError
239+
return errors.As(err, &aerr)
240+
}
241+
232242
// isNotFoundImageError heuristically attempts to determine whether an error
233243
// is saying the remote source couldn't find the image (as opposed to an
234244
// authentication error, an I/O error etc.)
235245
// TODO drive this into containers/image properly
236246
func isNotFoundImageError(err error) bool {
237247
return isDockerManifestUnknownError(err) ||
238-
errors.Is(err, ocilayout.ImageNotFoundError{})
248+
isOciImageNotFound(err)
239249
}
240250

241251
func (h *proxyHandler) openImageImpl(args []any, allowNotFound bool) (retReplyBuf replyBuf, retErr error) {

integration/proxy_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ func runTestOpenImageOptionalNotFound(p *proxy, img string) error {
332332
return nil
333333
}
334334

335+
// Verify that we do see an error if the parent directory doesn't exist
336+
func runTestOpenImageOptionalNoParentDirectory(p *proxy) error {
337+
_, err := p.callNoFd("OpenImageOptional", []any{"oci-archive:/no/such/parent/directory/foo.ociarchive"})
338+
if err == nil {
339+
return fmt.Errorf("Successfully opened nonexistent parent directory")
340+
}
341+
return nil
342+
}
343+
335344
func (s *proxySuite) TestProxy() {
336345
t := s.T()
337346
p, err := newProxy()
@@ -354,4 +363,14 @@ func (s *proxySuite) TestProxy() {
354363
err = fmt.Errorf("Testing optional image %s: %v", knownNotExtantImage, err)
355364
}
356365
assert.NoError(t, err)
366+
367+
nonExistentArchive := "oci-archive:/enoent"
368+
err = runTestOpenImageOptionalNotFound(p, nonExistentArchive)
369+
if err != nil {
370+
err = fmt.Errorf("Testing optional image %s: %v", nonExistentArchive, err)
371+
}
372+
assert.NoError(t, err)
373+
374+
err = runTestOpenImageOptionalNoParentDirectory(p)
375+
assert.NoError(t, err)
357376
}

vendor/github.com/containers/image/v5/oci/archive/oci_transport.go

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)