This commit is contained in:
Jakob Borg 2014-02-24 13:24:03 +01:00
parent c5bdaebf2b
commit e7bf3ac108
7 changed files with 19 additions and 16 deletions

View File

@ -17,7 +17,7 @@ func Blocks(r io.Reader, blocksize int) ([]Block, error) {
var blocks []Block var blocks []Block
var offset int64 var offset int64
for { for {
lr := &io.LimitedReader{r, int64(blocksize)} lr := &io.LimitedReader{R: r, N: int64(blocksize)}
hf := sha256.New() hf := sha256.New()
n, err := io.Copy(hf, lr) n, err := io.Copy(hf, lr)
if err != nil { if err != nil {

View File

@ -134,7 +134,7 @@ func (d *Discoverer) sendExtAnnouncements() {
} }
time.Sleep(d.ExtBroadcastIntv) time.Sleep(d.ExtBroadcastIntv)
} }
log.Println("discover/write: %v: stopping due to too many errors:", remote, err) log.Printf("discover/write: %v: stopping due to too many errors: %v", remote, err)
} }
func (d *Discoverer) recvAnnouncements() { func (d *Discoverer) recvAnnouncements() {

View File

@ -272,7 +272,7 @@ func TestFileQueueThreadHandling(t *testing.T) {
close(start) close(start)
wg.Wait() wg.Wait()
if int(gotTot) != total { if int(gotTot) != total {
t.Error("Total mismatch; %d != %d", gotTot, total) t.Errorf("Total mismatch; %d != %d", gotTot, total)
} }
} }
@ -283,13 +283,13 @@ func TestDeleteAt(t *testing.T) {
q.files = queuedFileList{{name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}} q.files = queuedFileList{{name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}}
q.deleteAt(i) q.deleteAt(i)
if l := len(q.files); l != 3 { if l := len(q.files); l != 3 {
t.Fatal("deleteAt(%d) failed; %d != 3", i, l) t.Fatalf("deleteAt(%d) failed; %d != 3", i, l)
} }
} }
q.files = queuedFileList{{name: "a"}} q.files = queuedFileList{{name: "a"}}
q.deleteAt(0) q.deleteAt(0)
if l := len(q.files); l != 0 { if l := len(q.files); l != 0 {
t.Fatal("deleteAt(only) failed; %d != 0", l) t.Fatalf("deleteAt(only) failed; %d != 0", l)
} }
} }

View File

@ -502,7 +502,10 @@ func saveIndex(m *Model) {
gzw := gzip.NewWriter(idxf) gzw := gzip.NewWriter(idxf)
protocol.IndexMessage{"local", m.ProtocolIndex()}.EncodeXDR(gzw) protocol.IndexMessage{
Repository: "local",
Files: m.ProtocolIndex(),
}.EncodeXDR(gzw)
gzw.Close() gzw.Close()
idxf.Close() idxf.Close()
os.Rename(fullName+".tmp", fullName) os.Rename(fullName+".tmp", fullName)

View File

@ -268,7 +268,7 @@ loop:
break loop break loop
} }
if hdr.version != 0 { if hdr.version != 0 {
c.close(fmt.Errorf("Protocol error: %s: unknown message version %#x", c.ID, hdr.version)) c.close(fmt.Errorf("Protocol error: %s: unknown message version %#x", c.id, hdr.version))
break loop break loop
} }
@ -371,7 +371,7 @@ loop:
} }
default: default:
c.close(fmt.Errorf("Protocol error: %s: unknown message type %#x", c.ID, hdr.msgType)) c.close(fmt.Errorf("Protocol error: %s: unknown message type %#x", c.id, hdr.msgType))
break loop break loop
} }
} }

View File

@ -99,16 +99,16 @@ func TestRequestResponseErr(t *testing.T) {
t.Errorf("Incorrect response data %q", string(d)) t.Errorf("Incorrect response data %q", string(d))
} }
if m0.repo != "default" { if m0.repo != "default" {
t.Error("Incorrect repo %q", m0.repo) t.Errorf("Incorrect repo %q", m0.repo)
} }
if m0.name != "tn" { if m0.name != "tn" {
t.Error("Incorrect name %q", m0.name) t.Errorf("Incorrect name %q", m0.name)
} }
if m0.offset != 1234 { if m0.offset != 1234 {
t.Error("Incorrect offset %d", m0.offset) t.Errorf("Incorrect offset %d", m0.offset)
} }
if m0.size != 5678 { if m0.size != 5678 {
t.Error("Incorrect size %d", m0.size) t.Errorf("Incorrect size %d", m0.size)
} }
t.Logf("Pass at %d+%d bytes", i, j) t.Logf("Pass at %d+%d bytes", i, j)
pass = true pass = true

View File

@ -21,7 +21,7 @@ func TestSuppressor(t *testing.T) {
// bw is 10000 / 10 = 1000 // bw is 10000 / 10 = 1000
t1 = t0.Add(10 * time.Second) t1 = t0.Add(10 * time.Second)
if bw := s.changes["foo"].bandwidth(t1); bw != 1000 { if bw := s.changes["foo"].bandwidth(t1); bw != 1000 {
t.Error("Incorrect bw %d", bw) t.Errorf("Incorrect bw %d", bw)
} }
sup, prev = s.suppress("foo", 10000, t1) sup, prev = s.suppress("foo", 10000, t1)
if sup { if sup {
@ -34,7 +34,7 @@ func TestSuppressor(t *testing.T) {
// bw is (10000 + 10000) / 11 = 1818 // bw is (10000 + 10000) / 11 = 1818
t1 = t0.Add(11 * time.Second) t1 = t0.Add(11 * time.Second)
if bw := s.changes["foo"].bandwidth(t1); bw != 1818 { if bw := s.changes["foo"].bandwidth(t1); bw != 1818 {
t.Error("Incorrect bw %d", bw) t.Errorf("Incorrect bw %d", bw)
} }
sup, prev = s.suppress("foo", 100500, t1) sup, prev = s.suppress("foo", 100500, t1)
if sup { if sup {
@ -47,7 +47,7 @@ func TestSuppressor(t *testing.T) {
// bw is (10000 + 10000 + 100500) / 12 = 10041 // bw is (10000 + 10000 + 100500) / 12 = 10041
t1 = t0.Add(12 * time.Second) t1 = t0.Add(12 * time.Second)
if bw := s.changes["foo"].bandwidth(t1); bw != 10041 { if bw := s.changes["foo"].bandwidth(t1); bw != 10041 {
t.Error("Incorrect bw %d", bw) t.Errorf("Incorrect bw %d", bw)
} }
sup, prev = s.suppress("foo", 10000000, t1) // value will be ignored sup, prev = s.suppress("foo", 10000000, t1) // value will be ignored
if !sup { if !sup {
@ -60,7 +60,7 @@ func TestSuppressor(t *testing.T) {
// bw is (10000 + 10000 + 100500) / 15 = 8033 // bw is (10000 + 10000 + 100500) / 15 = 8033
t1 = t0.Add(15 * time.Second) t1 = t0.Add(15 * time.Second)
if bw := s.changes["foo"].bandwidth(t1); bw != 8033 { if bw := s.changes["foo"].bandwidth(t1); bw != 8033 {
t.Error("Incorrect bw %d", bw) t.Errorf("Incorrect bw %d", bw)
} }
sup, prev = s.suppress("foo", 10000000, t1) sup, prev = s.suppress("foo", 10000000, t1)
if sup { if sup {