Skip to content

Commit d85d365

Browse files
authored
Merge pull request #58 from infosiftr/lookup-by-digest
Ensure our pre-flight HEAD request is always by-tag if we're pushing a tag
2 parents cab9251 + 4473698 commit d85d365

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

registry/push.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
var (
17-
// if a blob is more than this many bytes, we'll do a pre-flight HEAD request to verify whether we need to even bother pushing it before we do so (65535 is the theoretical maximum size of a single TCP packet, although MTU means it's usually closer to 1448 bytes, but this seemed like a sane place to draw a line to where a second request that might fail is worth our time)
17+
// if a manifest or blob is more than this many bytes, we'll do a pre-flight HEAD request to verify whether we need to even bother pushing it before we do so (65535 is the theoretical maximum size of a single TCP packet, although MTU means it's usually closer to 1448 bytes, but this seemed like a sane place to draw a line to where a second request that might fail is worth our time)
1818
BlobSizeWorthHEAD = int64(65535)
1919
)
2020

@@ -43,18 +43,25 @@ func EnsureManifest(ctx context.Context, ref Reference, manifest json.RawMessage
4343
return desc, fmt.Errorf("%s: failed getting client: %w", ref, err)
4444
}
4545

46-
// try HEAD request before pushing
47-
// if it matches, then we can assume child objects exist as well
48-
r, err := Lookup(ctx, ref, &LookupOptions{Head: true})
49-
if err != nil {
50-
return desc, fmt.Errorf("%s: failed HEAD: %w", ref, err)
51-
}
52-
// TODO if we had some kind of progress interface, this would be a great place for some kind of debug log of head's contents
53-
if r != nil {
54-
head := r.Descriptor()
55-
r.Close()
56-
if head.Digest == desc.Digest && head.Size == desc.Size {
57-
return head, nil
46+
if desc.Size > BlobSizeWorthHEAD {
47+
// try HEAD request before pushing
48+
// if it matches, then we can assume child objects exist as well
49+
headRef := ref
50+
if headRef.Tag != "" {
51+
// if this function is called with *both* tag *and* digest, the code below works correctly and pushes by tag and then validates by digest, but this lookup specifically will prefer the digest instead and skip when it shouldn't
52+
headRef.Digest = ""
53+
}
54+
r, err := Lookup(ctx, headRef, &LookupOptions{Head: true})
55+
if err != nil {
56+
return desc, fmt.Errorf("%s: failed HEAD: %w", ref, err)
57+
}
58+
// TODO if we had some kind of progress interface, this would be a great place for some kind of debug log of head's contents
59+
if r != nil {
60+
head := r.Descriptor()
61+
r.Close()
62+
if head.Digest == desc.Digest && head.Size == desc.Size {
63+
return head, nil
64+
}
5865
}
5966
}
6067

0 commit comments

Comments
 (0)