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:
parent
87c36b2cfb
commit
f5e76a0044
@ -2,6 +2,7 @@ package khepri
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -191,6 +192,8 @@ func (arch *Archiver) SaveFile(node *Node) error {
|
|||||||
chans := [](<-chan Blob){}
|
chans := [](<-chan Blob){}
|
||||||
defer chnker.Free()
|
defer chnker.Free()
|
||||||
|
|
||||||
|
chunks := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buf := GetChunkBuf("blob chunker")
|
buf := GetChunkBuf("blob chunker")
|
||||||
chunk, err := chnker.Next(buf)
|
chunk, err := chnker.Next(buf)
|
||||||
@ -204,6 +207,8 @@ func (arch *Archiver) SaveFile(node *Node) error {
|
|||||||
return arrar.Annotate(err, "SaveFile() chunker.Next()")
|
return arrar.Annotate(err, "SaveFile() chunker.Next()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chunks++
|
||||||
|
|
||||||
// acquire token, start goroutine to save chunk
|
// acquire token, start goroutine to save chunk
|
||||||
token := <-arch.blobToken
|
token := <-arch.blobToken
|
||||||
resCh := make(chan Blob, 1)
|
resCh := make(chan Blob, 1)
|
||||||
@ -229,6 +234,10 @@ func (arch *Archiver) SaveFile(node *Node) error {
|
|||||||
for _, ch := range chans {
|
for _, ch := range chans {
|
||||||
blobs = append(blobs, <-ch)
|
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))
|
node.Content = make([]backend.ID, len(blobs))
|
||||||
|
Loading…
Reference in New Issue
Block a user