forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
md_force_qr.go
89 lines (71 loc) · 1.82 KB
/
md_force_qr.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
func mdForceQROne(
ctx context.Context, config libkbfs.Config, tlfPath string,
dryRun bool) error {
// Get the latest head, and add a QR record up to that point.
irmd, _, err := mdGetMergedHeadForWriter(ctx, config, tlfPath)
if err != nil {
return err
}
rmdNext, err := irmd.MakeSuccessor(ctx, config.MetadataVersion(),
config.Codec(), config.Crypto(), config.KeyManager(),
irmd.MdID(), true)
if err != nil {
return err
}
// Pretend like we've done quota reclamation up through the
// current head.
gco := &libkbfs.GCOp{
LatestRev: irmd.Revision(),
}
rmdNext.AddOp(gco)
rmdNext.SetLastGCRevision(irmd.Revision())
fmt.Printf(
"Will put a forced QR op up to revision %d:\n", irmd.Revision())
err = mdDumpReadOnlyRMD(ctx, config, rmdNext.ReadOnly())
if err != nil {
return err
}
if dryRun {
fmt.Print("Dry-run set; not doing anything\n")
return nil
}
fmt.Printf("Putting revision %d...\n", rmdNext.Revision())
mdID, err := config.MDOps().Put(ctx, rmdNext)
if err != nil {
return err
}
fmt.Printf("New MD has id %s\n", mdID)
return nil
}
const mdForceQRUsageStr = `Usage:
kbfstool md forceQR /keybase/[public|private]/user1,assertion2
`
func mdForceQR(ctx context.Context, config libkbfs.Config,
args []string) (exitStatus int) {
flags := flag.NewFlagSet("kbfs md forceQR", flag.ContinueOnError)
dryRun := flags.Bool("d", false, "Dry run: don't actually do anything.")
err := flags.Parse(args)
if err != nil {
printError("md forceQR", err)
return 1
}
inputs := flags.Args()
if len(inputs) != 1 {
fmt.Print(mdForceQRUsageStr)
return 1
}
err = mdForceQROne(ctx, config, inputs[0], *dryRun)
if err != nil {
printError("md forceQR", err)
return 1
}
fmt.Print("\n")
return 0
}