Merge pull request #3408 from wangpeng168/master
fix: view snapshot is deleted before diff
This commit is contained in:
commit
adb8b02b66
@ -150,18 +150,11 @@ var diffCommand = cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var a, b []mount.Mount
|
desc, err = withMounts(ctx, idA, snapshotter, func(a []mount.Mount) (ocispec.Descriptor, error) {
|
||||||
ds := client.DiffService()
|
return withMounts(ctx, idB, snapshotter, func(b []mount.Mount) (ocispec.Descriptor, error) {
|
||||||
|
return client.DiffService().Compare(ctx, a, b, opts...)
|
||||||
a, err = getMounts(ctx, idA, snapshotter)
|
})
|
||||||
if err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
b, err = getMounts(ctx, idB, snapshotter)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
desc, err = ds.Compare(ctx, a, b, opts...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -177,26 +170,26 @@ var diffCommand = cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter) ([]mount.Mount, error) {
|
func withMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
|
||||||
var mounts []mount.Mount
|
var mounts []mount.Mount
|
||||||
info, err := sn.Stat(ctx, id)
|
info, err := sn.Stat(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return ocispec.Descriptor{}, err
|
||||||
}
|
}
|
||||||
if info.Kind == snapshots.KindActive {
|
if info.Kind == snapshots.KindActive {
|
||||||
mounts, err = sn.Mounts(ctx, id)
|
mounts, err = sn.Mounts(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return ocispec.Descriptor{}, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
key := fmt.Sprintf("%s-view-key", id)
|
key := fmt.Sprintf("%s-view-key", id)
|
||||||
mounts, err = sn.View(ctx, key, id)
|
mounts, err = sn.View(ctx, key, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return ocispec.Descriptor{}, err
|
||||||
}
|
}
|
||||||
defer sn.Remove(ctx, key)
|
defer sn.Remove(ctx, key)
|
||||||
}
|
}
|
||||||
return mounts, nil
|
return f(mounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
var usageCommand = cli.Command{
|
var usageCommand = cli.Command{
|
||||||
|
Loading…
Reference in New Issue
Block a user