forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsck.go
40 lines (36 loc) · 1.09 KB
/
fsck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package action
import (
"context"
"os"
"path/filepath"
"github.com/justwatchcom/gopass/config"
"github.com/justwatchcom/gopass/store/sub"
"github.com/justwatchcom/gopass/utils/fsutil"
"github.com/justwatchcom/gopass/utils/out"
"github.com/urfave/cli"
)
// Fsck checks the store integrity
func (s *Action) Fsck(ctx context.Context, c *cli.Context) error {
if c.IsSet("check") {
ctx = sub.WithFsckCheck(ctx, c.Bool("check"))
}
if c.IsSet("force") {
ctx = sub.WithFsckForce(ctx, c.Bool("force"))
}
// make sure config is in the right place
// we may have loaded it from one of the fallback locations
if err := s.cfg.Save(); err != nil {
return s.exitError(ctx, ExitConfig, err, "failed to save config: %s", err)
}
// clean up any previous config locations
oldCfg := filepath.Join(config.Homedir(), ".gopass.yml")
if fsutil.IsFile(oldCfg) {
if err := os.Remove(oldCfg); err != nil {
out.Red(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err)
}
}
if _, err := s.Store.Fsck(ctx, ""); err != nil {
return s.exitError(ctx, ExitFsck, err, "fsck found errors")
}
return nil
}