From 069baf6a66f5c63a82fb679ff2319ed2ee970fbd Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Thu, 26 Sep 2024 11:11:00 -0500 Subject: [PATCH] types: stat clone drops hidden proto fields The stat clone returned by protobuf returns a version of `types.Stat` that isn't compatible with some tests in buildkit. This changes clone to create a new type without cloning the hidden protobuf types. Signed-off-by: Jonathan A. Sternberg --- types/stat.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/types/stat.go b/types/stat.go index 9a5ae09e..466c8f85 100644 --- a/types/stat.go +++ b/types/stat.go @@ -19,5 +19,22 @@ func (s *Stat) Unmarshal(dAtA []byte) error { } func (s *Stat) Clone() *Stat { - return proto.Clone(s).(*Stat) + clone := &Stat{ + Path: s.Path, + Mode: s.Mode, + Uid: s.Uid, + Gid: s.Gid, + Size: s.Size, + ModTime: s.ModTime, + Linkname: s.Linkname, + Devmajor: s.Devmajor, + Devminor: s.Devminor, + } + if s.Xattrs != nil { + s.Xattrs = make(map[string][]byte, len(s.Xattrs)) + for k, v := range s.Xattrs { + clone.Xattrs[k] = v + } + } + return clone }