diff options
author | Rached Ben Mustapha <rached@benmur.net> | 2016-02-06 16:03:14 +0100 |
---|---|---|
committer | Rached Ben Mustapha <rached@benmur.net> | 2016-02-07 18:30:47 +0000 |
commit | ba35ca522a5a9be863f117ba4d716b63d7a20069 (patch) | |
tree | 79c9bdbb27257d1eead2094a2430a2454db9cb19 /cmd | |
parent | 0535490618d570c51a897a3d0cafcd5fdc83fa1d (diff) |
Handle pack loading errors in rebuild-index
Errors returned from backend.LoadAll() were not handled, leading to
these fatal errors from the unpacker trying to read the size from the end of
an empty buffer:
`seeking to read header length failed: bytes.Reader.Seek: negative position`
This change takes care of returning on error, as well as showing which pack
failed to load and validating pack integrity.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/restic/cmd_rebuild_index.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_rebuild_index.go index ee73992a6..27dae2392 100644 --- a/cmd/restic/cmd_rebuild_index.go +++ b/cmd/restic/cmd_rebuild_index.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "github.com/restic/restic/backend" "github.com/restic/restic/debug" @@ -137,6 +138,16 @@ func (cmd CmdRebuildIndex) RebuildIndex() error { h := backend.Handle{Type: backend.Data, Name: packID.String()} buf, err = backend.LoadAll(cmd.repo.Backend(), h, buf) + if err != nil { + debug.Log("RebuildIndex.RebuildIndex", "error while loading pack %v", packID.Str()) + return fmt.Errorf("error while loading pack %v: %v", packID.Str(), err) + } + + hash := backend.Hash(buf) + if !hash.Equal(packID) { + debug.Log("RebuildIndex.RebuildIndex", "Pack ID does not match, want %v, got %v", packID.Str(), hash.Str()) + return fmt.Errorf("Pack ID does not match, want %v, got %v", packID.Str(), hash.Str()) + } up, err := pack.NewUnpacker(cmd.repo.Key(), bytes.NewReader(buf)) if err != nil { |