-
Notifications
You must be signed in to change notification settings - Fork 0
/
md_force_qr.go
118 lines (95 loc) · 2.64 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"errors"
"flag"
"fmt"
"github.com/adamwalz/keybase-client/go/kbfs/kbfsmd"
"github.com/adamwalz/keybase-client/go/kbfs/libkbfs"
"github.com/adamwalz/keybase-client/go/protocol/keybase1"
"golang.org/x/net/context"
)
func mdForceQROne(
ctx context.Context, config libkbfs.Config,
replacements replacementMap, input string, dryRun bool) error {
tlfStr, branchStr, startStr, stopStr, err := mdSplitInput(input)
if err != nil {
return err
}
_, branchID, start, stop, err :=
mdParseInput(ctx, config, tlfStr, branchStr, startStr, stopStr)
if err != nil {
return err
}
if branchID != kbfsmd.NullBranchID {
return errors.New("force-qr doesn't support branch IDs")
}
if start != stop {
return errors.New("force-qr doesn't support revision ranges")
}
// Get the latest head, and add a QR record up to that point.
irmd, err := mdGetMergedHeadForWriter(ctx, config, tlfStr)
if err != nil {
return err
}
rmdNext, err := irmd.MakeSuccessor(ctx, config.MetadataVersion(),
config.Codec(), config.KeyManager(),
config.KBPKI(), config.KBPKI(), config, irmd.MdID(), true)
if err != nil {
return err
}
// Pretend like we've done quota reclamation up through the
// specified revision.
gco := &libkbfs.GCOp{
LatestRev: start,
}
rmdNext.AddOp(gco)
rmdNext.SetLastGCRevision(start)
fmt.Printf(
"Will put a forced QR op up to revision %d:\n", start)
err = mdDumpReadOnlyRMD(ctx, config, "md forceQR", replacements, 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())
session, err := config.KBPKI().GetCurrentSession(ctx)
if err != nil {
return err
}
newIrmd, err := config.MDOps().Put(
ctx, rmdNext, session.VerifyingKey, nil, keybase1.MDPriorityNormal, nil)
if err != nil {
return err
}
fmt.Printf("New MD has revision %v\n", newIrmd.Revision())
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
}
replacements := make(replacementMap)
err = mdForceQROne(ctx, config, replacements, inputs[0], *dryRun)
if err != nil {
printError("md forceQR", err)
return 1
}
fmt.Print("\n")
return 0
}