From c7cb1009a5cc1b503d68d5469b9dabfe77b2f959 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 20 Oct 2015 17:53:12 +1100 Subject: [PATCH] Fix #33. --- data/file/file.go | 15 +++++++++++---- torrent.go | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/data/file/file.go b/data/file/file.go index a24f4ebe..4725de74 100644 --- a/data/file/file.go +++ b/data/file/file.go @@ -109,18 +109,25 @@ func (me data) WriteSectionTo(w io.Writer, off, n int64) (written int64, err err if err != nil { return } - n1, err = io.Copy(w, io.NewSectionReader(f, off, n1)) + var w1 int64 + w1, err = io.Copy(w, io.NewSectionReader(f, off, n1)) f.Close() - if err != nil { + written += w1 + if w1 != n1 { + if err == nil || err == io.EOF { + err = io.ErrUnexpectedEOF + } return + } else { + err = nil } - written += n1 off = 0 n -= n1 if n == 0 { - break + return } } + err = io.EOF return } diff --git a/torrent.go b/torrent.go index e1ad41ca..7d3e235d 100644 --- a/torrent.go +++ b/torrent.go @@ -673,7 +673,7 @@ func (t *torrent) hashPiece(piece pp.Integer) (ps pieceSum) { return } if n != pl { - panic("lame") + panic(fmt.Sprintf("%T: %d != %d", t.data, n, pl)) } missinggo.CopyExact(ps[:], hash.Sum(nil)) return