Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oci): create blobs dir and define blobs dir name constant #520

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ import (
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/image-layout.md#indexjson-file
const ociImageIndexFile = "index.json"

// ociBlobsDir is the name of the blobs directory
// from the OCI Image Layout Specification.
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/image-layout.md#content
const ociBlobsDir = "blobs"

// Store implements `oras.Target`, and represents a content store
// based on file system with the OCI-Image layout.
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/image-layout.md
Expand Down Expand Up @@ -90,7 +95,7 @@ func NewWithContext(ctx context.Context, root string) (*Store, error) {
graph: graph.NewMemory(),
}

if err := ensureDir(rootAbs); err != nil {
if err := ensureDir(filepath.Join(rootAbs, ociBlobsDir)); err != nil {
return nil, err
}
if err := store.ensureOCILayoutFile(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions content/oci/readonlyoci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestReadOnlyStore(t *testing.T) {
// build fs
fsys := fstest.MapFS{}
for i, desc := range descs {
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
fsys[path] = &fstest.MapFile{Data: blobs[i]}
}
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestReadOnlyStore_Copy_OCIToMemory(t *testing.T) {
// build fs
fsys := fstest.MapFS{}
for i, desc := range descs {
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
fsys[path] = &fstest.MapFile{Data: blobs[i]}
}
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
Expand Down Expand Up @@ -717,7 +717,7 @@ func TestReadOnlyStore_Tags(t *testing.T) {
// build fs
fsys := fstest.MapFS{}
for i, desc := range descs {
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
fsys[path] = &fstest.MapFile{Data: blobs[i]}
}
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
Expand Down
2 changes: 1 addition & 1 deletion content/oci/readonlystorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ func blobPath(dgst digest.Digest) (string, error) {
return "", fmt.Errorf("cannot calculate blob path from invalid digest %s: %w: %v",
dgst.String(), errdef.ErrInvalidDigest, err)
}
return path.Join("blobs", dgst.Algorithm().String(), dgst.Encoded()), nil
return path.Join(ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()), nil
}
6 changes: 3 additions & 3 deletions content/oci/readonlystorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestReadOnlyStorage_Exists(t *testing.T) {
dgst := digest.FromBytes(blob)
desc := content.NewDescriptorFromBytes("", blob)
fsys := fstest.MapFS{
strings.Join([]string{"blobs", dgst.Algorithm().String(), dgst.Encoded()}, "/"): {},
strings.Join([]string{ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()}, "/"): {},
}
s := NewStorageFromFS(fsys)
ctx := context.Background()
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestReadOnlyStorage_Fetch(t *testing.T) {
dgst := digest.FromBytes(blob)
desc := content.NewDescriptorFromBytes("", blob)
fsys := fstest.MapFS{
strings.Join([]string{"blobs", dgst.Algorithm().String(), dgst.Encoded()}, "/"): {
strings.Join([]string{ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()}, "/"): {
Data: blob,
},
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestReadOnlyStorage_DirFS(t *testing.T) {
dgst := digest.FromBytes(blob)
desc := content.NewDescriptorFromBytes("test", blob)
// write blob to disk
path := filepath.Join(tempDir, "blobs", dgst.Algorithm().String(), dgst.Encoded())
path := filepath.Join(tempDir, ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded())
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
t.Fatal("error calling Mkdir(), error =", err)
}
Expand Down
2 changes: 1 addition & 1 deletion content/oci/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestStorage_Fetch_ExistingBlobs(t *testing.T) {
}

tempDir := t.TempDir()
path := filepath.Join(tempDir, "blobs", dgst.Algorithm().String(), dgst.Encoded())
path := filepath.Join(tempDir, ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded())
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
t.Fatal("error calling Mkdir(), error =", err)
}
Expand Down