From 8ea44e82d10fdce1139a55c7fef322ba9d0c282e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 31 Jul 2023 15:06:03 +0200 Subject: [PATCH] ffiwrapper: Correctly create unsealed file when doesn't exist --- storage/sealer/ffiwrapper/sealer_cgo.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/storage/sealer/ffiwrapper/sealer_cgo.go b/storage/sealer/ffiwrapper/sealer_cgo.go index 62ad43a4c..dc49729fe 100644 --- a/storage/sealer/ffiwrapper/sealer_cgo.go +++ b/storage/sealer/ffiwrapper/sealer_cgo.go @@ -10,6 +10,7 @@ import ( "crypto/rand" "encoding/base64" "encoding/json" + "errors" "io" "math/bits" "os" @@ -567,7 +568,14 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storiface.SectorRef, o pf, err = partialfile.OpenPartialFile(maxPieceSize, unsealedPath.Unsealed) if err != nil { - return xerrors.Errorf("opening partial file: %w", err) + if errors.Is(err, os.ErrNotExist) { + pf, err = partialfile.CreatePartialFile(maxPieceSize, unsealedPath.Unsealed) + if err != nil { + return xerrors.Errorf("creating partial file: %w", err) + } + } else { + return xerrors.Errorf("opening partial file: %w", err) + } } defer pf.Close() // nolint