Skip to content

Commit adb8b02

Browse files
authored
Merge pull request #3408 from wangpeng168/master
fix: view snapshot is deleted before diff
2 parents f2b6c31 + 4988424 commit adb8b02

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

cmd/ctr/commands/snapshots/snapshots.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,11 @@ var diffCommand = cli.Command{
150150
return err
151151
}
152152
} else {
153-
var a, b []mount.Mount
154-
ds := client.DiffService()
155-
156-
a, err = getMounts(ctx, idA, snapshotter)
157-
if err != nil {
158-
return err
159-
}
160-
b, err = getMounts(ctx, idB, snapshotter)
161-
if err != nil {
162-
return err
163-
}
164-
desc, err = ds.Compare(ctx, a, b, opts...)
153+
desc, err = withMounts(ctx, idA, snapshotter, func(a []mount.Mount) (ocispec.Descriptor, error) {
154+
return withMounts(ctx, idB, snapshotter, func(b []mount.Mount) (ocispec.Descriptor, error) {
155+
return client.DiffService().Compare(ctx, a, b, opts...)
156+
})
157+
})
165158
if err != nil {
166159
return err
167160
}
@@ -177,26 +170,26 @@ var diffCommand = cli.Command{
177170
},
178171
}
179172

180-
func getMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter) ([]mount.Mount, error) {
173+
func withMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
181174
var mounts []mount.Mount
182175
info, err := sn.Stat(ctx, id)
183176
if err != nil {
184-
return nil, err
177+
return ocispec.Descriptor{}, err
185178
}
186179
if info.Kind == snapshots.KindActive {
187180
mounts, err = sn.Mounts(ctx, id)
188181
if err != nil {
189-
return nil, err
182+
return ocispec.Descriptor{}, err
190183
}
191184
} else {
192185
key := fmt.Sprintf("%s-view-key", id)
193186
mounts, err = sn.View(ctx, key, id)
194187
if err != nil {
195-
return nil, err
188+
return ocispec.Descriptor{}, err
196189
}
197190
defer sn.Remove(ctx, key)
198191
}
199-
return mounts, nil
192+
return f(mounts)
200193
}
201194

202195
var usageCommand = cli.Command{

0 commit comments

Comments
 (0)