mirror of
https://github.com/octoleo/restic.git
synced 2024-12-28 04:56:04 +00:00
repository: move otherwise unused LoadIndex to tests
This commit is contained in:
parent
24474a36f4
commit
a12c5f1d37
@ -595,20 +595,6 @@ func (r *Repository) PrepareCache(indexIDs restic.IDSet) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadIndex loads the index id from backend and returns it.
|
|
||||||
func LoadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*Index, error) {
|
|
||||||
buf, err := repo.LoadAndDecrypt(ctx, nil, restic.IndexFile, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
idx, oldFormat, err := DecodeIndex(buf, id)
|
|
||||||
if oldFormat {
|
|
||||||
fmt.Fprintf(os.Stderr, "index %v has old format\n", id.Str())
|
|
||||||
}
|
|
||||||
return idx, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SearchKey finds a key with the supplied password, afterwards the config is
|
// SearchKey finds a key with the supplied password, afterwards the config is
|
||||||
// read and parsed. It tries at most maxKeys key files in the repo.
|
// read and parsed. It tries at most maxKeys key files in the repo.
|
||||||
func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int, keyHint string) error {
|
func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int, keyHint string) error {
|
||||||
|
@ -4,8 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -293,6 +295,20 @@ func TestRepositoryLoadIndex(t *testing.T) {
|
|||||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadIndex loads the index id from backend and returns it.
|
||||||
|
func loadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*repository.Index, error) {
|
||||||
|
buf, err := repo.LoadAndDecrypt(ctx, nil, restic.IndexFile, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
idx, oldFormat, err := repository.DecodeIndex(buf, id)
|
||||||
|
if oldFormat {
|
||||||
|
fmt.Fprintf(os.Stderr, "index %v has old format\n", id.Str())
|
||||||
|
}
|
||||||
|
return idx, err
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkLoadIndex(b *testing.B) {
|
func BenchmarkLoadIndex(b *testing.B) {
|
||||||
repository.TestUseLowSecurityKDFParameters(b)
|
repository.TestUseLowSecurityKDFParameters(b)
|
||||||
|
|
||||||
@ -323,7 +339,7 @@ func BenchmarkLoadIndex(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_, err := repository.LoadIndex(context.TODO(), repo, id)
|
_, err := loadIndex(context.TODO(), repo, id)
|
||||||
rtest.OK(b, err)
|
rtest.OK(b, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,7 +389,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) {
|
|||||||
packEntries := make(map[restic.ID]map[restic.ID]struct{})
|
packEntries := make(map[restic.ID]map[restic.ID]struct{})
|
||||||
|
|
||||||
err := repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error {
|
err := repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error {
|
||||||
idx, err := repository.LoadIndex(context.TODO(), repo, id)
|
idx, err := loadIndex(context.TODO(), repo, id)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
for pb := range idx.Each(context.TODO()) {
|
for pb := range idx.Each(context.TODO()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user