diff: resplit Applier from Differ
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
committed by
Derek McGowan
parent
b268261446
commit
b580441f91
26
diff/diff.go
26
diff/diff.go
@@ -24,21 +24,33 @@ type Config struct {
|
||||
// Opt is used to configure a diff operation
|
||||
type Opt func(*Config) error
|
||||
|
||||
// Differ allows the apply and creation of filesystem diffs between mounts
|
||||
// Differ allows creation of filesystem diffs between mounts
|
||||
type Differ interface {
|
||||
// Diff computes the difference between two mounts and returns a
|
||||
// descriptor for the computed diff. The options can provide
|
||||
// a ref which can be used to track the content creation of the diff.
|
||||
// The media type which is used to determine the format of the created
|
||||
// content can also be provided as an option.
|
||||
Diff(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error)
|
||||
}
|
||||
|
||||
// Applier allows applying diffs between mounts
|
||||
type Applier interface {
|
||||
// Apply applies the content referred to by the given descriptor to
|
||||
// the provided mount. The method of applying is based on the
|
||||
// implementation and content descriptor. For example, in the common
|
||||
// case the descriptor is a file system difference in tar format,
|
||||
// that tar would be applied on top of the mounts.
|
||||
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
|
||||
}
|
||||
|
||||
// DiffMounts computes the difference between two mounts and returns a
|
||||
// descriptor for the computed diff. The options can provide
|
||||
// a ref which can be used to track the content creation of the diff.
|
||||
// The media type which is used to determine the format of the created
|
||||
// content can also be provided as an option.
|
||||
DiffMounts(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error)
|
||||
// DiffApplier is the interface that groups the basic Apply and Diff methods.
|
||||
//
|
||||
// golint says `type name will be used as diff.DiffApplier by other packages, and that stutters`,
|
||||
// but that can be ignored now.
|
||||
type DiffApplier interface { // nolint: golint
|
||||
Applier
|
||||
Differ
|
||||
}
|
||||
|
||||
// WithMediaType sets the media type to use for creating the diff, without
|
||||
|
||||
@@ -51,9 +51,9 @@ type walkingDiff struct {
|
||||
|
||||
var emptyDesc = ocispec.Descriptor{}
|
||||
|
||||
// NewWalkingDiff is a generic implementation of diff.Differ.
|
||||
// NewWalkingDiff is a generic implementation of diff.DiffApplier.
|
||||
// NewWalkingDiff is expected to work with any filesystem.
|
||||
func NewWalkingDiff(store content.Store) (diff.Differ, error) {
|
||||
func NewWalkingDiff(store content.Store) (diff.DiffApplier, error) {
|
||||
return &walkingDiff{
|
||||
store: store,
|
||||
}, nil
|
||||
@@ -125,9 +125,9 @@ func (s *walkingDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
|
||||
return ocidesc, nil
|
||||
}
|
||||
|
||||
// DiffMounts creates a diff between the given mounts and uploads the result
|
||||
// Diff creates a diff between the given mounts and uploads the result
|
||||
// to the content store.
|
||||
func (s *walkingDiff) DiffMounts(ctx context.Context, lower, upper []mount.Mount, opts ...diff.Opt) (d ocispec.Descriptor, err error) {
|
||||
func (s *walkingDiff) Diff(ctx context.Context, lower, upper []mount.Mount, opts ...diff.Opt) (d ocispec.Descriptor, err error) {
|
||||
var config diff.Config
|
||||
for _, opt := range opts {
|
||||
if err := opt(&config); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user