2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 06:07:44 +00:00

Add safety check: count chunks and compare to blobs

This commit is contained in:
Alexander Neumann 2014-11-30 22:49:14 +01:00
parent 87c36b2cfb
commit f5e76a0044

View File

@ -2,6 +2,7 @@ package khepri
import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
@ -191,6 +192,8 @@ func (arch *Archiver) SaveFile(node *Node) error {
chans := [](<-chan Blob){}
defer chnker.Free()
chunks := 0
for {
buf := GetChunkBuf("blob chunker")
chunk, err := chnker.Next(buf)
@ -204,6 +207,8 @@ func (arch *Archiver) SaveFile(node *Node) error {
return arrar.Annotate(err, "SaveFile() chunker.Next()")
}
chunks++
// acquire token, start goroutine to save chunk
token := <-arch.blobToken
resCh := make(chan Blob, 1)
@ -229,6 +234,10 @@ func (arch *Archiver) SaveFile(node *Node) error {
for _, ch := range chans {
blobs = append(blobs, <-ch)
}
if len(blobs) != chunks {
return fmt.Errorf("chunker returned %v chunks, but only %v blobs saved", chunks, len(blobs))
}
}
node.Content = make([]backend.ID, len(blobs))