1/*
2   Copyright The containerd Authors.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17package plugin
18
19import (
20	"github.com/containerd/containerd/diff"
21	"github.com/containerd/containerd/diff/apply"
22	"github.com/containerd/containerd/diff/walking"
23	"github.com/containerd/containerd/metadata"
24	"github.com/containerd/containerd/platforms"
25	"github.com/containerd/containerd/plugin"
26)
27
28func init() {
29	plugin.Register(&plugin.Registration{
30		Type: plugin.DiffPlugin,
31		ID:   "walking",
32		Requires: []plugin.Type{
33			plugin.MetadataPlugin,
34		},
35		InitFn: func(ic *plugin.InitContext) (interface{}, error) {
36			md, err := ic.Get(plugin.MetadataPlugin)
37			if err != nil {
38				return nil, err
39			}
40
41			ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
42			cs := md.(*metadata.DB).ContentStore()
43
44			return diffPlugin{
45				Comparer: walking.NewWalkingDiff(cs),
46				Applier:  apply.NewFileSystemApplier(cs),
47			}, nil
48		},
49	})
50}
51
52type diffPlugin struct {
53	diff.Comparer
54	diff.Applier
55}
56