Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fsck progress bar. Mostly. #2303

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/action/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
func (s *Action) Fsck(c *cli.Context) error {
_ = s.rem.Reset("fsck")

filter := c.Args().First()

ctx := ctxutil.WithGlobalFlags(c)
if c.IsSet("decrypt") {
ctx = leaf.WithFsckDecrypt(ctx, c.Bool("decrypt"))
Expand Down Expand Up @@ -46,16 +48,24 @@ func (s *Action) Fsck(c *cli.Context) error {
}

pwList := t.List(tree.INF)
if filter != "" {
// We restrict ourselves to the filter.
t, err := t.FindFolder(filter)
if err != nil {
return exit.Error(exit.NotFound, nil, "Entry %q not found", filter)
}
pwList = t.List(tree.INF)
}

bar := termio.NewProgressBar(int64(len(pwList) * 2))
bar := termio.NewProgressBar(int64(len(pwList)) + 1)
bar.Hidden = ctxutil.IsHidden(ctx)
ctx = ctxutil.WithProgressCallback(ctx, func() {
bar.Inc()
})
ctx = out.AddPrefix(ctx, "\n")

// the main work in done by the sub stores.
if err := s.Store.Fsck(ctx, c.Args().Get(0)); err != nil {
if err := s.Store.Fsck(ctx, filter); err != nil {
return exit.Error(exit.Fsck, err, "fsck found errors: %s", err)
}
bar.Done()
Expand Down
4 changes: 0 additions & 4 deletions internal/backend/storage/fs/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ import (
"syscall"

"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/debug"
"github.com/gopasspw/gopass/pkg/fsutil"
"github.com/gopasspw/gopass/pkg/termio"
)

// Fsck checks the storage integrity.
func (s *Store) Fsck(ctx context.Context) error {
pcb := ctxutil.GetProgressCallback(ctx)

entries, err := s.List(ctx, "")
if err != nil {
return err
}

dirs := make(map[string]struct{}, len(entries))
for _, entry := range entries {
pcb()
debug.Log("checking entry %q", entry)

filename := filepath.Join(s.path, entry)
Expand Down
14 changes: 6 additions & 8 deletions internal/store/leaf/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func (s *Store) Fsck(ctx context.Context, path string) error {
debug.Log("Checking %s", path)

// first let the storage backend check itself
out.Printf(ctx, "Checking storage backend")
debug.Log("Checking storage backend")
if err := s.storage.Fsck(ctx); err != nil {
return fmt.Errorf("storage backend found: %w", err)
return fmt.Errorf("storage backend error: %w", err)
}

// then try to compact storage / rcs
out.Printf(ctx, "Compacting storage if possible")
debug.Log("Compacting storage")
if err := s.storage.Compact(ctx); err != nil {
return fmt.Errorf("storage backend compaction failed: %w", err)
}
Expand All @@ -37,17 +37,15 @@ func (s *Store) Fsck(ctx context.Context, path string) error {

// then we'll make sure all the secrets are readable by us and every
// valid recipient
if path == "" {
out.Printf(ctx, "Checking all secrets in store")
} else {
if path != "" {
out.Printf(ctx, "Checking all secrets matching %s", path)
}

names, err := s.List(ctx, path)
if err != nil {
return fmt.Errorf("failed to list entries for %s: %w", path, err)
}

debug.Log("names (%d): %q", len(names), names)
sort.Strings(names)
for _, name := range names {
pcb()
Expand All @@ -63,7 +61,7 @@ func (s *Store) Fsck(ctx context.Context, path string) error {
}

if err := s.storage.Push(ctx, "", ""); err != nil {
if errors.Is(err, store.ErrGitNoRemote) {
if !errors.Is(err, store.ErrGitNoRemote) {
out.Printf(ctx, "RCS Push failed: %s", err)
}
}
Expand Down