mirror of
https://github.com/octoleo/restic.git
synced 2024-11-16 10:05:25 +00:00
Add progress option to index
This commit is contained in:
parent
8d735cf6a9
commit
8de6e5a627
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
"restic/debug"
|
"restic/debug"
|
||||||
"restic/list"
|
"restic/list"
|
||||||
@ -41,16 +42,21 @@ func newIndex() *Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new index for repo from scratch.
|
// New creates a new index for repo from scratch.
|
||||||
func New(repo types.Repository) (*Index, error) {
|
func New(repo types.Repository, p *restic.Progress) (*Index, error) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
|
||||||
|
p.Start()
|
||||||
|
defer p.Done()
|
||||||
|
|
||||||
ch := make(chan worker.Job)
|
ch := make(chan worker.Job)
|
||||||
go list.AllPacks(repo, ch, done)
|
go list.AllPacks(repo, ch, done)
|
||||||
|
|
||||||
idx := newIndex()
|
idx := newIndex()
|
||||||
|
|
||||||
for job := range ch {
|
for job := range ch {
|
||||||
|
p.Report(restic.Stat{Blobs: 1})
|
||||||
|
|
||||||
packID := job.Data.(backend.ID)
|
packID := job.Data.(backend.ID)
|
||||||
if job.Error != nil {
|
if job.Error != nil {
|
||||||
fmt.Fprintf(os.Stderr, "unable to list pack %v: %v\n", packID.Str(), job.Error)
|
fmt.Fprintf(os.Stderr, "unable to list pack %v: %v\n", packID.Str(), job.Error)
|
||||||
@ -105,9 +111,12 @@ func loadIndexJSON(repo types.Repository, id backend.ID) (*indexJSON, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load creates an index by loading all index files from the repo.
|
// Load creates an index by loading all index files from the repo.
|
||||||
func Load(repo types.Repository) (*Index, error) {
|
func Load(repo types.Repository, p *restic.Progress) (*Index, error) {
|
||||||
debug.Log("index.Load", "loading indexes")
|
debug.Log("index.Load", "loading indexes")
|
||||||
|
|
||||||
|
p.Start()
|
||||||
|
defer p.Done()
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
|
||||||
@ -117,6 +126,8 @@ func Load(repo types.Repository) (*Index, error) {
|
|||||||
index := newIndex()
|
index := newIndex()
|
||||||
|
|
||||||
for id := range repo.List(backend.Index, done) {
|
for id := range repo.List(backend.Index, done) {
|
||||||
|
p.Report(restic.Stat{Blobs: 1})
|
||||||
|
|
||||||
debug.Log("index.Load", "Load index %v", id.Str())
|
debug.Log("index.Load", "Load index %v", id.Str())
|
||||||
idx, err := loadIndexJSON(repo, id)
|
idx, err := loadIndexJSON(repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,7 +40,7 @@ func TestIndexNew(t *testing.T) {
|
|||||||
repo, cleanup := createFilledRepo(t, 3, 0)
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
idx, err := New(repo)
|
idx, err := New(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("New() returned error %v", err)
|
t.Fatalf("New() returned error %v", err)
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func TestIndexLoad(t *testing.T) {
|
|||||||
repo, cleanup := createFilledRepo(t, 3, 0)
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
loadIdx, err := Load(repo)
|
loadIdx, err := Load(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Load() returned error %v", err)
|
t.Fatalf("Load() returned error %v", err)
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func TestIndexLoad(t *testing.T) {
|
|||||||
|
|
||||||
validateIndex(t, repo, loadIdx)
|
validateIndex(t, repo, loadIdx)
|
||||||
|
|
||||||
newIdx, err := New(repo)
|
newIdx, err := New(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("New() returned error %v", err)
|
t.Fatalf("New() returned error %v", err)
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func BenchmarkIndexNew(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
idx, err := New(repo)
|
idx, err := New(repo, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("New() returned error %v", err)
|
b.Fatalf("New() returned error %v", err)
|
||||||
@ -162,7 +162,7 @@ func TestIndexDuplicateBlobs(t *testing.T) {
|
|||||||
repo, cleanup := createFilledRepo(t, 3, 0.01)
|
repo, cleanup := createFilledRepo(t, 3, 0.01)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
idx, err := New(repo)
|
idx, err := New(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ func TestIndexDuplicateBlobs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadIndex(t testing.TB, repo *repository.Repository) *Index {
|
func loadIndex(t testing.TB, repo *repository.Repository) *Index {
|
||||||
idx, err := Load(repo)
|
idx, err := Load(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Load() returned error %v", err)
|
t.Fatalf("Load() returned error %v", err)
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ func TestIndexAddRemovePack(t *testing.T) {
|
|||||||
repo, cleanup := createFilledRepo(t, 3, 0)
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
idx, err := Load(repo)
|
idx, err := Load(repo, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Load() returned error %v", err)
|
t.Fatalf("Load() returned error %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user