Skip to content

Commit 63522d9

Browse files
authored
Merge pull request #2390 from AkihiroSuda/fix-schema1
fix schema1 fetchBlob()
2 parents 356b0d5 + 703c25e commit 63522d9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

client_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ func TestImagePullSomePlatforms(t *testing.T) {
291291
}
292292
}
293293

294+
func TestImagePullSchema1(t *testing.T) {
295+
client, err := newClient(t, address)
296+
if err != nil {
297+
t.Fatal(err)
298+
}
299+
defer client.Close()
300+
301+
ctx, cancel := testContext()
302+
defer cancel()
303+
schema1TestImage := "gcr.io/google_containers/pause:3.0@sha256:0d093c962a6c2dd8bb8727b661e2b5f13e9df884af9945b4cc7088d9350cd3ee"
304+
_, err = client.Pull(ctx, schema1TestImage, WithPlatform(platforms.Default()), WithSchema1Conversion)
305+
if err != nil {
306+
t.Fatal(err)
307+
}
308+
}
309+
294310
func TestClientReconnect(t *testing.T) {
295311
t.Parallel()
296312

remotes/docker/schema1/converter.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
257257
var (
258258
ref = remotes.MakeRefKey(ctx, desc)
259259
calc = newBlobStateCalculator()
260-
size = desc.Size
261260
)
262261

263262
// size may be unknown, set to zero for content ingest
264-
if size == -1 {
265-
size = 0
263+
ingestDesc := desc
264+
if ingestDesc.Size == -1 {
265+
ingestDesc.Size = 0
266266
}
267267

268-
cw, err := content.OpenWriter(ctx, c.contentStore, content.WithRef(ref), content.WithDescriptor(desc))
268+
cw, err := content.OpenWriter(ctx, c.contentStore, content.WithRef(ref), content.WithDescriptor(ingestDesc))
269269
if err != nil {
270270
if !errdefs.IsAlreadyExists(err) {
271271
return err
@@ -317,7 +317,7 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
317317
eg.Go(func() error {
318318
defer pw.Close()
319319

320-
return content.Copy(ctx, cw, io.TeeReader(rc, pw), size, desc.Digest)
320+
return content.Copy(ctx, cw, io.TeeReader(rc, pw), ingestDesc.Size, ingestDesc.Digest)
321321
})
322322

323323
if err := eg.Wait(); err != nil {

0 commit comments

Comments
 (0)