move prompt code into daemon.go
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
Jeromy committed
Jul 20, 2016 at 03:14 UTC
fcc4f0001d968ced8db8fcce12327a89a97e7d1b
3 files changed
+28
-31
cmd/ipfs/daemon.go
+27
-3
@@ -228,10 +228,15 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
228
fmt.Println("Found old repo version, migrations need to be run.")
229
230
if !found {
231
- err = migrate.TryMigrating(fsrepo.RepoVersion)
232
- } else if domigrate {
233
- err = migrate.RunMigration(fsrepo.RepoVersion)
231
+ domigrate = YesNoPrompt("Run migrations automatically? [y/N]")
232
}
233
+
234
+ if !domigrate {
235
+ res.SetError(fmt.Errorf("please run the migrations manually"), cmds.ErrNormal)
236
+ return
237
+ }
238
+
239
+ err = migrate.RunMigration(fsrepo.RepoVersion)
240
if err != nil {
241
res.SetError(err, cmds.ErrNormal)
242
return
@@ -594,3 +599,22 @@ func merge(cs ...<-chan error) <-chan error {
599
}()
600
return out
601
}
602
+
603
+func YesNoPrompt(prompt string) bool {
604
+ var s string
605
+ for i := 0; i < 3; i++ {
606
+ fmt.Printf("%s ", prompt)
607
+ fmt.Scanf("%s", &s)
608
+ switch s {
609
+ case "y", "Y":
610
+ return true
611
+ case "n", "N":
612
+ return false
613
+ case "":
614
+ return false
615
+ }
616
+ fmt.Println("Please press either 'y' or 'n'")
617
+ }
618
+
619
+ return false
620
+}
repo/fsrepo/migrations/mfsr.go
-27
@@ -59,30 +59,3 @@ type VersionFileNotFound string
59
func (v VersionFileNotFound) Error() string {
60
return "no version file in repo at " + string(v)
61
}
62
-
63
-func TryMigrating(tovers int) error {
64
- if !YesNoPrompt("Run migrations automatically? [y/N]") {
65
- return fmt.Errorf("please run the migrations manually")
66
- }
67
-
68
- return RunMigration(tovers)
69
-}
70
-
71
-func YesNoPrompt(prompt string) bool {
72
- var s string
73
- for i := 0; i < 3; i++ {
74
- fmt.Printf("%s ", prompt)
75
- fmt.Scanf("%s", &s)
76
- switch s {
77
- case "y", "Y":
78
- return true
79
- case "n", "N":
80
- return false
81
- case "":
82
- return false
83
- }
84
- fmt.Println("Please press either 'y' or 'n'")
85
- }
86
-
87
- return false
88
-}
test/sharness/t0066-migration.sh
+1
-1
@@ -27,7 +27,7 @@ test_expect_success "ipfs daemon --migrate=false fails" '
27
'
28
29
test_expect_success "output looks good" '
30
- grep "ipfs repo needs migration" false_out
30
+ grep "please run the migrations manually" false_out
31
'
32
33
test_expect_success "ipfs daemon --migrate=true runs migration" '