From 7f9d2277255b5b7b08a22f91cf596dfca4f01a19 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 15 Aug 2016 21:10:20 +0200 Subject: [PATCH] Use progress in prune command --- src/cmds/restic/cmd_prune.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cmds/restic/cmd_prune.go b/src/cmds/restic/cmd_prune.go index d9306c34c..0761b3c30 100644 --- a/src/cmds/restic/cmd_prune.go +++ b/src/cmds/restic/cmd_prune.go @@ -82,13 +82,6 @@ func (cmd CmdPrune) Execute(args []string) error { done := make(chan struct{}) defer close(done) - cmd.global.Verbosef("building new index for repo\n") - - idx, err := index.New(repo) - if err != nil { - return err - } - var stats struct { blobs int packs int @@ -96,6 +89,19 @@ func (cmd CmdPrune) Execute(args []string) error { bytes int64 } + cmd.global.Verbosef("counting files in repo\n") + for _ = range repo.List(backend.Data, done) { + stats.packs++ + } + + cmd.global.Verbosef("building new index for repo\n") + + bar := newProgressMax(cmd.global.ShowProgress(), uint64(stats.packs), "files") + idx, err := index.New(repo, bar) + if err != nil { + return err + } + for _, pack := range idx.Packs { stats.bytes += pack.Size } @@ -137,7 +143,7 @@ func (cmd CmdPrune) Execute(args []string) error { usedBlobs := pack.NewBlobSet() seenBlobs := pack.NewBlobSet() - bar := newProgressMax(cmd.global.ShowProgress(), uint64(len(snapshots)), "snapshots") + bar = newProgressMax(cmd.global.ShowProgress(), uint64(len(snapshots)), "snapshots") bar.Start() for _, sn := range snapshots { debug.Log("CmdPrune.Execute", "process snapshot %v", sn.ID().Str()) @@ -175,7 +181,8 @@ func (cmd CmdPrune) Execute(args []string) error { cmd.global.Verbosef("creating new index\n") - idx, err = index.New(repo) + bar = newProgressMax(cmd.global.ShowProgress(), uint64(stats.packs), "files") + idx, err = index.New(repo, bar) if err != nil { return err }