From d3f5e0c90eab380c6b6a25e602fb021cec68baf8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 17 Oct 2023 12:30:19 +0200 Subject: [PATCH] images/archive: replace hardcoded strings for OCI-spec consts Signed-off-by: Sebastiaan van Stijn --- images/archive/exporter.go | 10 ++++------ images/archive/importer.go | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/images/archive/exporter.go b/images/archive/exporter.go index b0617b430..460939ce4 100644 --- a/images/archive/exporter.go +++ b/images/archive/exporter.go @@ -320,10 +320,9 @@ func blobRecord(cs content.Provider, desc ocispec.Descriptor, opts *blobRecordOp if opts != nil && opts.blobFilter != nil && !opts.blobFilter(desc) { return tarRecord{} } - path := path.Join("blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()) return tarRecord{ Header: &tar.Header{ - Name: path, + Name: path.Join(ocispec.ImageBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()), Mode: 0444, Size: desc.Size, Typeflag: tar.TypeReg, @@ -403,7 +402,7 @@ func ociIndexRecord(manifests []ocispec.Descriptor) tarRecord { return tarRecord{ Header: &tar.Header{ - Name: "index.json", + Name: ocispec.ImageIndexFile, Mode: 0644, Size: int64(len(b)), Typeflag: tar.TypeReg, @@ -443,10 +442,9 @@ func manifestsRecord(ctx context.Context, store content.Provider, manifests map[ if err := dgst.Validate(); err != nil { return tarRecord{}, err } - mfsts[i].Config = path.Join("blobs", dgst.Algorithm().String(), dgst.Encoded()) + mfsts[i].Config = path.Join(ocispec.ImageBlobsDir, dgst.Algorithm().String(), dgst.Encoded()) for _, l := range manifest.Layers { - path := path.Join("blobs", l.Digest.Algorithm().String(), l.Digest.Encoded()) - mfsts[i].Layers = append(mfsts[i].Layers, path) + mfsts[i].Layers = append(mfsts[i].Layers, path.Join(ocispec.ImageBlobsDir, l.Digest.Algorithm().String(), l.Digest.Encoded())) } for _, name := range m.names { diff --git a/images/archive/importer.go b/images/archive/importer.go index 22a621814..094808365 100644 --- a/images/archive/importer.go +++ b/images/archive/importer.go @@ -133,7 +133,7 @@ func ImportIndex(ctx context.Context, store content.Store, reader io.Reader, opt return ocispec.Descriptor{}, fmt.Errorf("unsupported OCI version %s", ociLayout.Version) } - idx, ok := blobs["index.json"] + idx, ok := blobs[ocispec.ImageIndexFile] if !ok { return ocispec.Descriptor{}, fmt.Errorf("missing index.json in OCI layout %s", ocispec.ImageLayoutVersion) }