Skip to content

Commit d424f9f

Browse files
committed
WIP INCOMPLETE: Sketch digest choice approach in transports
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 319ac44 commit d424f9f

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

image/copy/blob.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ func (ic *imageCopier) copyBlobFromStream(ctx context.Context, srcReader io.Read
9898

9999
// === Finally, send the layer stream to dest.
100100
options := private.PutBlobOptions{
101-
Cache: ic.c.blobInfoCache,
102-
IsConfig: isConfig,
103-
EmptyLayer: emptyLayer,
104-
Digests: ic.c.options.DigestOptions,
101+
Cache: ic.c.blobInfoCache,
102+
IsConfig: isConfig,
103+
EmptyLayer: emptyLayer,
104+
Digests: ic.c.options.DigestOptions,
105+
CannotChangeDigest: ic.cannotModifyManifestReason != "", // FIXME: does this structurally guarantee that stream.info.Digest is known?
105106
}
106107
if !isConfig {
107108
options.LayerIndex = &layerIndex

image/directory/directory_dest.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/opencontainers/go-digest"
1313
"github.com/sirupsen/logrus"
14+
"go.podman.io/image/v5/internal/digests"
1415
"go.podman.io/image/v5/internal/imagedestination/impl"
1516
"go.podman.io/image/v5/internal/imagedestination/stubs"
1617
"go.podman.io/image/v5/internal/private"
@@ -150,7 +151,11 @@ func (d *dirImageDestination) PutBlobWithOptions(ctx context.Context, stream io.
150151
}
151152
}()
152153

153-
digester, stream := putblobdigest.DigestIfUnknown(stream, inputInfo)
154+
algorithm, err := options.Digests.Choose(digests.Situation{Preexisting: inputInfo.Digest, CannotChangeAlgorithm: options.CannotChangeDigest})
155+
if err != nil {
156+
return private.UploadedBlob{}, err
157+
}
158+
digester, stream := putblobdigest.DigestIfAlgorithmUnknown(stream, inputInfo, algorithm)
154159

155160
// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
156161
size, err := io.Copy(blobFile, stream)

image/internal/private/private.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ type PutBlobOptions struct {
112112
// if they use internal/imagedestination/impl.Compat;
113113
// in that case, they will all be consistently zero-valued.
114114

115-
EmptyLayer bool // True if the blob is an "empty"/"throwaway" layer, and may not necessarily be physically represented.
116-
LayerIndex *int // If the blob is a layer, a zero-based index of the layer within the image; nil otherwise.
117-
Digests digests.Options // Also a new private field, but mandatory requests are enforced by the compatibility wrapper.
115+
EmptyLayer bool // True if the blob is an "empty"/"throwaway" layer, and may not necessarily be physically represented.
116+
LayerIndex *int // If the blob is a layer, a zero-based index of the layer within the image; nil otherwise.
117+
Digests digests.Options // Also a new private field, but mandatory requests are enforced by the compatibility wrapper.
118+
CannotChangeDigest bool // True if PutBlobWithOptions is provided with a digest and the destination must use precisely that one (in particular, use that algorithm).
118119
}
119120

120121
// PutBlobPartialOptions are used in PutBlobPartial.

0 commit comments

Comments
 (0)