mirror of
https://github.com/octoleo/restic.git
synced 2024-10-31 19:02:32 +00:00
Add safety check: count chunks and compare to blobs
This commit is contained in:
parent
87c36b2cfb
commit
f5e76a0044
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user