Skip to content

Commit 4c1fa57

Browse files
author
Aaron Lehmann
committed
remotes/docker: Only return "already exists" on push when the upload was successful
The `(dockerPusher).Push` method uses a `StatusTracker` to check if an upload already happened, before repeating the upload. However, there is no provision for failure handling. If a PUT request returns an error, the `StatusTracker` will still see the upload as if it happened successfully. Add a status boolean so that only successful uploads short-circuit `Push`. Signed-off-by: Aaron Lehmann <[email protected]>
1 parent dc8af03 commit 4c1fa57

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

remotes/docker/pusher.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
5252
ref := remotes.MakeRefKey(ctx, desc)
5353
status, err := p.tracker.GetStatus(ref)
5454
if err == nil {
55-
if status.Offset == status.Total {
55+
if status.Committed && status.Offset == status.Total {
5656
return nil, errors.Wrapf(errdefs.ErrAlreadyExists, "ref %v", ref)
5757
}
5858
// TODO: Handle incomplete status
@@ -341,8 +341,6 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
341341
if err := pw.pipe.Close(); err != nil {
342342
return err
343343
}
344-
// TODO: Update status to determine committing
345-
346344
// TODO: timeout waiting for response
347345
resp := <-pw.responseC
348346
if resp.err != nil {
@@ -379,6 +377,10 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
379377
return errors.Errorf("got digest %s, expected %s", actual, expected)
380378
}
381379

380+
status.Committed = true
381+
status.UpdatedAt = time.Now()
382+
pw.tracker.SetStatus(pw.ref, status)
383+
382384
return nil
383385
}
384386

remotes/docker/status.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
type Status struct {
2929
content.Status
3030

31+
Committed bool
32+
3133
// UploadUUID is used by the Docker registry to reference blob uploads
3234
UploadUUID string
3335
}

0 commit comments

Comments
 (0)