aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-06 18:19:43 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-06 18:19:43 +0200
commit656a2c10b177e7fafc0b4bbddf3c634c642a2221 (patch)
treee583a1e7dc532516f8f1bba21bab36aaa46ca4d4 /repo.go
parente2d64a027a72f7db99d98ab9652f3e509b86d344 (diff)
downloaddna-backup-656a2c10b177e7fafc0b4bbddf3c634c642a2221.tar.gz
dna-backup-656a2c10b177e7fafc0b4bbddf3c634c642a2221.zip
fixes: chunk id starts from 0 & nil check
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/repo.go b/repo.go
index cd5178b..8bd069a 100644
--- a/repo.go
+++ b/repo.go
@@ -36,6 +36,7 @@ import (
"os"
"path"
"path/filepath"
+ "reflect"
"github.com/chmduquesne/rollinghash/rabinkarp64"
)
@@ -219,6 +220,7 @@ func storeChunks(dest string, chunks <-chan []byte) {
}
}
+// TODO: use atoi for chunkid
func (r *Repo) loadChunks(versions []string, chunks chan<- IdentifiedChunk) {
for i, v := range versions {
p := path.Join(v, chunksName)
@@ -336,8 +338,8 @@ func (r *Repo) encodeTempChunk(temp BufferedChunk, version int, last *uint64) (c
return
}
if chunk.Len() == r.chunkSize {
- *last++
id := &ChunkId{Ver: version, Idx: *last}
+ *last++
ic := NewLoadedChunk(id, temp.Bytes())
hasher := rabinkarp64.NewFromPol(r.pol)
r.hashAndStoreChunk(ic, hasher)
@@ -349,7 +351,7 @@ func (r *Repo) encodeTempChunk(temp BufferedChunk, version int, last *uint64) (c
}
func (r *Repo) encodeTempChunks(prev BufferedChunk, curr BufferedChunk, version int, last *uint64) []Chunk {
- if prev == nil {
+ if reflect.ValueOf(prev).IsNil() {
c, _ := r.encodeTempChunk(curr, version, last)
return []Chunk{c}
} else if curr.Len() < r.chunkMinLen() {
@@ -371,7 +373,7 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk {
var chunks []Chunk
var prev *TempChunk
var last uint64
- bufStream := bufio.NewReaderSize(stream, r.chunkSize)
+ bufStream := bufio.NewReaderSize(stream, r.chunkSize*2)
buff := make([]byte, 0, r.chunkSize*2)
n, err := io.ReadFull(stream, buff[:r.chunkSize])
if n < r.chunkSize {