cmd_rebuild_index: Remove calls to GetReader()

This commit is contained in:
Alexander Neumann 2016-01-24 00:21:03 +01:00
parent 61551b0591
commit 2c3a6a6fa9
1 changed files with 5 additions and 24 deletions

View File

@ -2,8 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"io"
"io/ioutil"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
@ -126,6 +124,7 @@ func (cmd CmdRebuildIndex) RebuildIndex() error {
cmd.global.Printf("checking for additional packs\n") cmd.global.Printf("checking for additional packs\n")
newPacks := 0 newPacks := 0
var buf []byte
for packID := range cmd.repo.List(backend.Data, done) { for packID := range cmd.repo.List(backend.Data, done) {
if packsDone.Has(packID) { if packsDone.Has(packID) {
continue continue
@ -134,27 +133,12 @@ func (cmd CmdRebuildIndex) RebuildIndex() error {
debug.Log("RebuildIndex.RebuildIndex", "pack %v not indexed", packID.Str()) debug.Log("RebuildIndex.RebuildIndex", "pack %v not indexed", packID.Str())
newPacks++ newPacks++
rd, err := cmd.repo.Backend().GetReader(backend.Data, packID.String(), 0, 0) var err error
if err != nil {
debug.Log("RebuildIndex.RebuildIndex", "GetReader returned error: %v", err)
return err
}
var readSeeker io.ReadSeeker h := backend.Handle{Type: backend.Data, Name: packID.String()}
if r, ok := rd.(io.ReadSeeker); ok { buf, err = backend.LoadAll(cmd.repo.Backend(), h, buf)
debug.Log("RebuildIndex.RebuildIndex", "reader is seekable")
readSeeker = r
} else {
debug.Log("RebuildIndex.RebuildIndex", "reader is not seekable, loading contents to ram")
buf, err := ioutil.ReadAll(rd)
if err != nil {
return err
}
readSeeker = bytes.NewReader(buf) up, err := pack.NewUnpacker(cmd.repo.Key(), bytes.NewReader(buf))
}
up, err := pack.NewUnpacker(cmd.repo.Key(), readSeeker)
if err != nil { if err != nil {
debug.Log("RebuildIndex.RebuildIndex", "error while unpacking pack %v", packID.Str()) debug.Log("RebuildIndex.RebuildIndex", "error while unpacking pack %v", packID.Str())
return err return err
@ -171,9 +155,6 @@ func (cmd CmdRebuildIndex) RebuildIndex() error {
}) })
} }
err = rd.Close()
debug.Log("RebuildIndex.RebuildIndex", "error closing reader for pack %v: %v", packID.Str(), err)
if repository.IndexFull(combinedIndex) { if repository.IndexFull(combinedIndex) {
combinedIndex, err = cmd.storeIndex(combinedIndex) combinedIndex, err = cmd.storeIndex(combinedIndex)
if err != nil { if err != nil {