Merge pull request #3123 from stefanberger/extend_apply_call_with_options_parameter
Extend Applier's Apply() method with an optional options parameter
This commit is contained in:
commit
2ec2089b05
10
diff.go
10
diff.go
@ -45,9 +45,15 @@ type diffRemote struct {
|
|||||||
client diffapi.DiffClient
|
client diffapi.DiffClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *diffRemote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) {
|
func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) {
|
||||||
|
var config diff.ApplyConfig
|
||||||
|
for _, opt := range opts {
|
||||||
|
if err := opt(&config); err != nil {
|
||||||
|
return ocispec.Descriptor{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
req := &diffapi.ApplyRequest{
|
req := &diffapi.ApplyRequest{
|
||||||
Diff: fromDescriptor(diff),
|
Diff: fromDescriptor(desc),
|
||||||
Mounts: fromMounts(mounts),
|
Mounts: fromMounts(mounts),
|
||||||
}
|
}
|
||||||
resp, err := r.client.Apply(ctx, req)
|
resp, err := r.client.Apply(ctx, req)
|
||||||
|
@ -53,7 +53,7 @@ var emptyDesc = ocispec.Descriptor{}
|
|||||||
// Apply applies the content associated with the provided digests onto the
|
// Apply applies the content associated with the provided digests onto the
|
||||||
// provided mounts. Archive content will be extracted and decompressed if
|
// provided mounts. Archive content will be extracted and decompressed if
|
||||||
// necessary.
|
// necessary.
|
||||||
func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
|
func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -51,6 +51,13 @@ type Comparer interface {
|
|||||||
Compare(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error)
|
Compare(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyConfig is used to hold parameters needed for a apply operation
|
||||||
|
type ApplyConfig struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyOpt is used to configure an Apply operation
|
||||||
|
type ApplyOpt func(*ApplyConfig) error
|
||||||
|
|
||||||
// Applier allows applying diffs between mounts
|
// Applier allows applying diffs between mounts
|
||||||
type Applier interface {
|
type Applier interface {
|
||||||
// Apply applies the content referred to by the given descriptor to
|
// Apply applies the content referred to by the given descriptor to
|
||||||
@ -58,7 +65,7 @@ type Applier interface {
|
|||||||
// implementation and content descriptor. For example, in the common
|
// implementation and content descriptor. For example, in the common
|
||||||
// case the descriptor is a file system difference in tar format,
|
// case the descriptor is a file system difference in tar format,
|
||||||
// that tar would be applied on top of the mounts.
|
// that tar would be applied on top of the mounts.
|
||||||
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
|
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount, opts ...ApplyOpt) (ocispec.Descriptor, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithMediaType sets the media type to use for creating the diff, without
|
// WithMediaType sets the media type to use for creating the diff, without
|
||||||
|
@ -95,7 +95,7 @@ func NewWindowsLcowDiff(store content.Store) (CompareApplier, error) {
|
|||||||
// Apply applies the content associated with the provided digests onto the
|
// Apply applies the content associated with the provided digests onto the
|
||||||
// provided mounts. Archive content will be extracted and decompressed if
|
// provided mounts. Archive content will be extracted and decompressed if
|
||||||
// necessary.
|
// necessary.
|
||||||
func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
|
func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -87,7 +87,7 @@ func NewWindowsDiff(store content.Store) (CompareApplier, error) {
|
|||||||
// Apply applies the content associated with the provided digests onto the
|
// Apply applies the content associated with the provided digests onto the
|
||||||
// provided mounts. Archive content will be extracted and decompressed if
|
// provided mounts. Archive content will be extracted and decompressed if
|
||||||
// necessary.
|
// necessary.
|
||||||
func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
|
func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -99,8 +99,10 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C
|
|||||||
mounts = toMounts(er.Mounts)
|
mounts = toMounts(er.Mounts)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var opts []diff.ApplyOpt
|
||||||
|
|
||||||
for _, differ := range l.differs {
|
for _, differ := range l.differs {
|
||||||
ocidesc, err = differ.Apply(ctx, desc, mounts)
|
ocidesc, err = differ.Apply(ctx, desc, mounts, opts...)
|
||||||
if !errdefs.IsNotImplemented(err) {
|
if !errdefs.IsNotImplemented(err) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user