Merge pull request #9230 from filecoin-project/fix/data-cid-close

fix: api: DataCid - ensure reader is closed
This commit is contained in:
Łukasz Magiera 2022-08-29 16:15:03 +02:00 committed by GitHub
commit 78cde92999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,6 +53,16 @@ func (sb *Sealer) NewSector(ctx context.Context, sector storiface.SectorRef) err
} }
func (sb *Sealer) DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData storiface.Data) (abi.PieceInfo, error) { func (sb *Sealer) DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData storiface.Data) (abi.PieceInfo, error) {
origPieceData := pieceData
defer func() {
closer, ok := origPieceData.(io.Closer)
if !ok {
log.Warnf("DataCid: cannot close pieceData reader %T because it is not an io.Closer", origPieceData)
return
}
closer.Close() //nolint:errcheck
}()
pieceData = io.LimitReader(io.MultiReader( pieceData = io.LimitReader(io.MultiReader(
pieceData, pieceData,
nullreader.Reader{}, nullreader.Reader{},