Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d98454

Browse files
committedSep 18, 2023
ociarchive: Return ImageNotFound if the file isn't present
This is for containers/skopeo#2114 which is in turn a dependency of coreos/rpm-ostree#4598 Basically I want to map ENOENT to `ImageNotFound`, because the build tooling wants to treat "target image is not present" differently from "DNS lookup failed" or "we got EPERM". There's a bit of code motion here because we need to move the `os.Open()` call before creating a temporary directory.
1 parent 27b3a7e commit 1d98454

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed
 

‎oci/archive/oci_transport.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io/fs"
78
"os"
89
"strings"
910

@@ -171,18 +172,24 @@ func createOCIRef(sys *types.SystemContext, image string) (tempDirOCIRef, error)
171172

172173
// creates the temporary directory and copies the tarred content to it
173174
func createUntarTempDir(sys *types.SystemContext, ref ociArchiveReference) (tempDirOCIRef, error) {
174-
tempDirRef, err := createOCIRef(sys, ref.image)
175-
if err != nil {
176-
return tempDirOCIRef{}, fmt.Errorf("creating oci reference: %w", err)
177-
}
178175
src := ref.resolvedFile
179-
dst := tempDirRef.tempDirectory
180176
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
181177
arch, err := os.Open(src)
182178
if err != nil {
183-
return tempDirOCIRef{}, err
179+
if errors.Is(err, fs.ErrNotExist) {
180+
return tempDirOCIRef{}, ImageNotFoundError{ref: ref}
181+
} else {
182+
return tempDirOCIRef{}, err
183+
}
184184
}
185185
defer arch.Close()
186+
187+
tempDirRef, err := createOCIRef(sys, ref.image)
188+
if err != nil {
189+
return tempDirOCIRef{}, fmt.Errorf("creating oci reference: %w", err)
190+
}
191+
dst := tempDirRef.tempDirectory
192+
186193
if err := archive.NewDefaultArchiver().Untar(arch, dst, &archive.TarOptions{NoLchown: true}); err != nil {
187194
if err := tempDirRef.deleteTempDir(); err != nil {
188195
return tempDirOCIRef{}, fmt.Errorf("deleting temp directory %q: %w", tempDirRef.tempDirectory, err)

0 commit comments

Comments
 (0)
Please sign in to comment.