ffiwrapper: Fix AddPiece with multireaders

This commit is contained in:
Łukasz Magiera 2020-06-09 21:54:52 +02:00
parent 57adda40f9
commit 52782b6def
2 changed files with 20 additions and 7 deletions

View File

@ -117,20 +117,30 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector abi.SectorID, existingPie
var pieceCids []abi.PieceInfo
for {
n, err := pr.Read(buf[:])
if err != nil && err != io.EOF {
return abi.PieceInfo{}, xerrors.Errorf("pr read error: %w", err)
var read int
for rbuf := buf; len(rbuf) > 0; {
n, err := pr.Read(rbuf)
if err != nil && err != io.EOF {
return abi.PieceInfo{}, xerrors.Errorf("pr read error: %w", err)
}
rbuf = rbuf[n:]
read += n
if err == io.EOF {
break
}
}
if err == io.EOF {
if read == 0 {
break
}
c, err := sb.pieceCid(buf[:n])
c, err := sb.pieceCid(buf[:read])
if err != nil {
return abi.PieceInfo{}, xerrors.Errorf("pieceCid error: %w", err)
}
pieceCids = append(pieceCids, abi.PieceInfo{
Size: abi.UnpaddedPieceSize(len(buf[:n])).Padded(),
Size: abi.UnpaddedPieceSize(len(buf[:read])).Padded(),
PieceCID: c,
})
}

View File

@ -45,7 +45,10 @@ type seal struct {
}
func data(sn abi.SectorNumber, dlen abi.UnpaddedPieceSize) io.Reader {
return io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(dlen))
return io.MultiReader(
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(123)),
io.LimitReader(rand.New(rand.NewSource(42+int64(sn))), int64(dlen-123)),
)
}
func (s *seal) precommit(t *testing.T, sb *Sealer, id abi.SectorID, done func()) {