mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 19:38:57 +00:00
Merge pull request 2044 from restic/fix-verify
restore: Close files tested with --verify
This commit is contained in:
commit
e4b39ae553
@ -306,25 +306,33 @@ func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) {
|
|||||||
return errors.Errorf("Invalid file size: expected %d got %d", node.Size, stat.Size())
|
return errors.Errorf("Invalid file size: expected %d got %d", node.Size, stat.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
offset := int64(0)
|
offset := int64(0)
|
||||||
for _, blobID := range node.Content {
|
for _, blobID := range node.Content {
|
||||||
rd, err := os.Open(target)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
blobs, _ := res.repo.Index().Lookup(blobID, restic.DataBlob)
|
blobs, _ := res.repo.Index().Lookup(blobID, restic.DataBlob)
|
||||||
length := blobs[0].Length - uint(crypto.Extension)
|
length := blobs[0].Length - uint(crypto.Extension)
|
||||||
buf := make([]byte, length) // TODO do I want to reuse the buffer somehow?
|
buf := make([]byte, length) // TODO do I want to reuse the buffer somehow?
|
||||||
_, err = rd.ReadAt(buf, offset)
|
_, err = file.ReadAt(buf, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = file.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !blobID.Equal(restic.Hash(buf)) {
|
if !blobID.Equal(restic.Hash(buf)) {
|
||||||
|
_ = file.Close()
|
||||||
return errors.Errorf("Unexpected contents starting at offset %d", offset)
|
return errors.Errorf("Unexpected contents starting at offset %d", offset)
|
||||||
}
|
}
|
||||||
offset += int64(length)
|
offset += int64(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
leaveDir: func(node *restic.Node, target, location string) error { return nil },
|
leaveDir: func(node *restic.Node, target, location string) error { return nil },
|
||||||
|
Loading…
Reference in New Issue
Block a user