v1.27.0-a #10
@ -102,15 +102,37 @@ func OpenPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*PartialFil
|
||||
return nil, xerrors.Errorf("openning partial file '%s': %w", path, err)
|
||||
}
|
||||
|
||||
st, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("stat '%s': %w", path, err)
|
||||
}
|
||||
if st.Size() < int64(maxPieceSize) {
|
||||
return nil, xerrors.Errorf("sector file '%s' was smaller than the sector size %d < %d", path, st.Size(), maxPieceSize)
|
||||
}
|
||||
if st.Size() == int64(maxPieceSize) {
|
||||
log.Debugw("no partial file trailer, assuming fully allocated", "path", path)
|
||||
|
||||
allAlloc := &rlepluslazy.RunSliceIterator{Runs: []rlepluslazy.Run{{Val: true, Len: uint64(maxPieceSize)}}}
|
||||
enc, err := rlepluslazy.EncodeRuns(allAlloc, []byte{})
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("encoding full allocation: %w", err)
|
||||
}
|
||||
|
||||
rle, err := rlepluslazy.FromBuf(enc)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("decoding full allocation: %w", err)
|
||||
}
|
||||
|
||||
return &PartialFile{
|
||||
maxPiece: maxPieceSize,
|
||||
path: path,
|
||||
allocated: rle,
|
||||
file: f,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var rle rlepluslazy.RLE
|
||||
err = func() error {
|
||||
st, err := f.Stat()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("stat '%s': %w", path, err)
|
||||
}
|
||||
if st.Size() < int64(maxPieceSize) {
|
||||
return xerrors.Errorf("sector file '%s' was smaller than the sector size %d < %d", path, st.Size(), maxPieceSize)
|
||||
}
|
||||
// read trailer
|
||||
var tlen [4]byte
|
||||
_, err = f.ReadAt(tlen[:], st.Size()-int64(len(tlen)))
|
||||
|
Loading…
Reference in New Issue
Block a user