From 848930ab5a9ec2a99ae5250723dc2c175390a09d Mon Sep 17 00:00:00 2001 From: tnextday Date: Tue, 8 Dec 2015 17:43:52 +0800 Subject: [PATCH] fix forever loop problem --- go/storage/volume_replicate.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/go/storage/volume_replicate.go b/go/storage/volume_replicate.go index 4ca21f105..f40cf60da 100644 --- a/go/storage/volume_replicate.go +++ b/go/storage/volume_replicate.go @@ -123,14 +123,14 @@ func (cdr *CleanReader) WriteTo(w io.Writer) (written int64, err error) { if nextDirty != nil { sz = nextDirty.Offset - off } - if sz > 0 { - if n, e = io.CopyN(w, cdr.DataFile, sz); e != nil { - return - } - } else { - if n, e = io.Copy(w, cdr.DataFile); e != nil { - return - } + if sz <= 0 { + // copy until eof + n, e = io.Copy(w, cdr.DataFile); + written += n + return + } + if n, e = io.CopyN(w, cdr.DataFile, sz); e != nil { + return } off += n written += n