From e3d3887a0b2b2c18b4c5e6f26c56b1dc34d3e009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 26 May 2020 21:08:51 +0200 Subject: [PATCH] Address review --- ffiwrapper/partialfile.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ffiwrapper/partialfile.go b/ffiwrapper/partialfile.go index a278e7347..e7f89302e 100644 --- a/ffiwrapper/partialfile.go +++ b/ffiwrapper/partialfile.go @@ -32,13 +32,14 @@ type partialFile struct { file *os.File } -func writeTrailer(psz int64, w *os.File, r rlepluslazy.RunIterator) error { +func writeTrailer(maxPieceSize int64, w *os.File, r rlepluslazy.RunIterator) error { trailer, err := rlepluslazy.EncodeRuns(r, nil) if err != nil { return xerrors.Errorf("encoding trailer: %w", err) } - if _, err := w.Seek(psz, io.SeekStart); err != nil { + // maxPieceSize == unpadded(sectorSize) == trailer start + if _, err := w.Seek(maxPieceSize, io.SeekStart); err != nil { return xerrors.Errorf("seek to trailer start: %w", err) } @@ -51,7 +52,7 @@ func writeTrailer(psz int64, w *os.File, r rlepluslazy.RunIterator) error { return xerrors.Errorf("writing trailer length: %w", err) } - return w.Truncate(psz + int64(rb) + 4) + return w.Truncate(maxPieceSize + int64(rb) + 4) } func createPartialFile(maxPieceSize abi.UnpaddedPieceSize, path string) (*partialFile, error) {