Fix ffiwrapper unseal
This commit is contained in:
parent
10f7750d80
commit
1bbfb7cffd
@ -108,15 +108,23 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector abi.SectorID, existingPie
|
|||||||
}, werr()
|
}, werr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type closerFunc func() error
|
||||||
|
|
||||||
|
func (cf closerFunc) Close() error {
|
||||||
|
return cf()
|
||||||
|
}
|
||||||
|
|
||||||
func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.SectorID, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealedCID cid.Cid) (io.ReadCloser, error) {
|
func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.SectorID, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealedCID cid.Cid) (io.ReadCloser, error) {
|
||||||
path, doneUnsealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed, stores.FTUnsealed, false)
|
{
|
||||||
|
path, doneUnsealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed, stores.FTNone, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("acquire unsealed sector path: %w", err)
|
return nil, xerrors.Errorf("acquire unsealed sector path: %w", err)
|
||||||
}
|
}
|
||||||
defer doneUnsealed()
|
|
||||||
f, err := os.OpenFile(path.Unsealed, os.O_RDONLY, 0644)
|
f, err := os.OpenFile(path.Unsealed, os.O_RDONLY, 0644)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if _, err := f.Seek(int64(offset), io.SeekStart); err != nil {
|
if _, err := f.Seek(int64(offset), io.SeekStart); err != nil {
|
||||||
|
doneUnsealed()
|
||||||
return nil, xerrors.Errorf("seek: %w", err)
|
return nil, xerrors.Errorf("seek: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,14 +135,21 @@ func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.Sect
|
|||||||
io.Closer
|
io.Closer
|
||||||
}{
|
}{
|
||||||
Reader: lr,
|
Reader: lr,
|
||||||
Closer: f,
|
Closer: closerFunc(func() error {
|
||||||
|
doneUnsealed()
|
||||||
|
return f.Close()
|
||||||
|
}),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doneUnsealed()
|
||||||
|
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sealed, doneSealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed|stores.FTCache, 0, false)
|
paths, doneSealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTSealed|stores.FTCache, stores.FTUnsealed, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("acquire sealed/cache sector path: %w", err)
|
return nil, xerrors.Errorf("acquire sealed/cache sector path: %w", err)
|
||||||
}
|
}
|
||||||
@ -145,9 +160,9 @@ func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.Sect
|
|||||||
// remove last used one (or use whatever other cache policy makes sense))
|
// remove last used one (or use whatever other cache policy makes sense))
|
||||||
err = ffi.Unseal(
|
err = ffi.Unseal(
|
||||||
sb.sealProofType,
|
sb.sealProofType,
|
||||||
sealed.Cache,
|
paths.Cache,
|
||||||
sealed.Sealed,
|
paths.Sealed,
|
||||||
path.Unsealed,
|
paths.Unsealed,
|
||||||
sector.Number,
|
sector.Number,
|
||||||
sector.Miner,
|
sector.Miner,
|
||||||
ticket,
|
ticket,
|
||||||
@ -157,7 +172,7 @@ func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.Sect
|
|||||||
return nil, xerrors.Errorf("unseal failed: %w", err)
|
return nil, xerrors.Errorf("unseal failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err = os.OpenFile(string(path.Unsealed), os.O_RDONLY, 0644)
|
f, err := os.OpenFile(paths.Unsealed, os.O_RDONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user