1
0
mirror of https://github.com/moby/buildkit.git synced 2025-07-30 15:03:06 +03:00

fix bug that gen layer tar contains duplicated files

Signed-off-by: frankyang <yyb196@gmail.com>
This commit is contained in:
frankyang
2023-11-21 17:50:18 +08:00
parent d5817ceadf
commit 10e03e595d

13
cache/blobs_linux.go vendored
View File

@ -43,14 +43,27 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
if err != nil { if err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to open writer") return emptyDesc, false, errors.Wrap(err, "failed to open writer")
} }
defer func() { defer func() {
if cw != nil { if cw != nil {
// after commit success cw will be set to nil, if cw isn't nil, error
// happened before commit, we should abort this ingest, and because the
// error may incured by ctx cancel, use a new context here. And since
// cm.Close will unlock this ref in the content store, we invoke abort
// to remove the ingest root in advance.
if aerr := sr.cm.ContentStore.Abort(context.Background(), ref); aerr != nil {
bklog.G(ctx).WithError(aerr).Warnf("failed to abort writer %q", ref)
}
if cerr := cw.Close(); cerr != nil { if cerr := cw.Close(); cerr != nil {
bklog.G(ctx).WithError(cerr).Warnf("failed to close writer %q", ref) bklog.G(ctx).WithError(cerr).Warnf("failed to close writer %q", ref)
} }
} }
}() }()
if err = cw.Truncate(0); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to truncate writer")
}
bufW := bufio.NewWriterSize(cw, 128*1024) bufW := bufio.NewWriterSize(cw, 128*1024)
var labels map[string]string var labels map[string]string
if compressorFunc != nil { if compressorFunc != nil {