Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 985123b

Browse files
authored
Fix up mutable_source interface a bit more to make it usable from outside this package. (#190)
1 parent e57f9f2 commit 985123b

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

pkg/image/mutable_source.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,21 @@ func NewMutableSource(r types.ImageReference) (*MutableSource, error) {
6161
return ms, nil
6262
}
6363

64-
// GetManifest marshals the stored manifest to the byte format.
64+
// Manifest marshals the stored manifest to the byte format.
6565
func (m *MutableSource) GetManifest(_ *digest.Digest) ([]byte, string, error) {
66-
s, err := json.Marshal(m.mfst)
6766
if err := m.saveConfig(); err != nil {
6867
return nil, "", err
6968
}
69+
s, err := json.Marshal(m.mfst)
70+
if err != nil {
71+
return nil, "", err
72+
}
7073
return s, manifest.DockerV2Schema2MediaType, err
7174
}
7275

7376
// populateManifestAndConfig parses the raw manifest and configs, storing them on the struct.
7477
func (m *MutableSource) populateManifestAndConfig() error {
75-
mfstBytes, _, err := m.GetManifest(nil)
78+
mfstBytes, _, err := m.ProxySource.GetManifest(nil)
7679
if err != nil {
7780
return err
7881
}
@@ -116,7 +119,7 @@ func gzipBytes(b []byte) ([]byte, error) {
116119
}
117120

118121
// appendLayer appends an uncompressed blob to the image, preserving the invariants required across the config and manifest.
119-
func (m *MutableSource) appendLayer(content []byte) error {
122+
func (m *MutableSource) AppendLayer(content []byte) error {
120123
compressedBlob, err := gzipBytes(content)
121124
if err != nil {
122125
return err

pkg/image/mutable_source_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var testCases = []struct {
6868
},
6969
}
7070

71-
func TestMutableSource_appendLayer(t *testing.T) {
71+
func TestMutableSource_AppendLayer(t *testing.T) {
7272
for _, tt := range testCases {
7373
t.Run(tt.name, func(t *testing.T) {
7474
m := &MutableSource{
@@ -77,8 +77,8 @@ func TestMutableSource_appendLayer(t *testing.T) {
7777
extraBlobs: make(map[string][]byte),
7878
}
7979

80-
if err := m.appendLayer([]byte(tt.args.content)); (err != nil) != tt.wantErr {
81-
t.Fatalf("MutableSource.appendLayer() error = %v, wantErr %v", err, tt.wantErr)
80+
if err := m.AppendLayer([]byte(tt.args.content)); (err != nil) != tt.wantErr {
81+
t.Fatalf("MutableSource.AppendLayer() error = %v, wantErr %v", err, tt.wantErr)
8282
}
8383
if err := m.saveConfig(); err != nil {
8484
t.Fatalf("Error saving config: %v", err)

pkg/image/proxy_types.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ func (p *ProxySource) LayerInfosForCopy() []types.BlobInfo {
5555
// ProxyReference implements types.Reference by proxying calls to an underlying implementation.
5656
type ProxyReference struct {
5757
types.ImageReference
58-
src types.ImageSource
58+
Src types.ImageSource
5959
}
6060

6161
func (p *ProxyReference) NewImageSource(ctx *types.SystemContext) (types.ImageSource, error) {
62-
return p.src, nil
63-
}
64-
65-
func (p *ProxyReference) NewImageDestination(ctx *types.SystemContext) (types.ImageDestination, error) {
66-
return p.ImageReference.NewImageDestination(ctx)
62+
return p.Src, nil
6763
}

0 commit comments

Comments
 (0)