mount: Add From/ToProto helpers

Helpers to convert from containerd's [Mount] to its protobuf structure for
[Mount] and vice-versa appear three times. It seems sane to just expose
this facility in /mount.

Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
Danny Canter
2023-06-28 04:03:18 -07:00
parent 9b4ed8acc2
commit 55a8102ec1
7 changed files with 49 additions and 99 deletions

View File

@@ -60,7 +60,7 @@ func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
req := &diffapi.ApplyRequest{
Diff: fromDescriptor(desc),
Mounts: fromMounts(mounts),
Mounts: mount.ToProto(mounts),
Payloads: payloads,
}
resp, err := r.client.Apply(ctx, req)
@@ -85,8 +85,8 @@ func (r *diffRemote) Compare(ctx context.Context, a, b []mount.Mount, opts ...di
sourceDateEpoch = timestamppb.New(*config.SourceDateEpoch)
}
req := &diffapi.DiffRequest{
Left: fromMounts(a),
Right: fromMounts(b),
Left: mount.ToProto(a),
Right: mount.ToProto(b),
MediaType: config.MediaType,
Ref: config.Reference,
Labels: config.Labels,
@@ -119,16 +119,3 @@ func fromDescriptor(d ocispec.Descriptor) *types.Descriptor {
Annotations: d.Annotations,
}
}
func fromMounts(mounts []mount.Mount) []*types.Mount {
apiMounts := make([]*types.Mount, len(mounts))
for i, m := range mounts {
apiMounts[i] = &types.Mount{
Type: m.Type,
Source: m.Source,
Target: m.Target,
Options: m.Options,
}
}
return apiMounts
}