提交 fcc4f000 作者: Jeromy

move prompt code into daemon.go

License: MIT
Signed-off-by: 's avatarJeromy <why@ipfs.io>
上级 fd732d2d
...@@ -228,10 +228,15 @@ func daemonFunc(req cmds.Request, res cmds.Response) { ...@@ -228,10 +228,15 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
fmt.Println("Found old repo version, migrations need to be run.") fmt.Println("Found old repo version, migrations need to be run.")
if !found { if !found {
err = migrate.TryMigrating(fsrepo.RepoVersion) domigrate = YesNoPrompt("Run migrations automatically? [y/N]")
} else if domigrate { }
err = migrate.RunMigration(fsrepo.RepoVersion)
if !domigrate {
res.SetError(fmt.Errorf("please run the migrations manually"), cmds.ErrNormal)
return
} }
err = migrate.RunMigration(fsrepo.RepoVersion)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
...@@ -594,3 +599,22 @@ func merge(cs ...<-chan error) <-chan error { ...@@ -594,3 +599,22 @@ func merge(cs ...<-chan error) <-chan error {
}() }()
return out return out
} }
func YesNoPrompt(prompt string) bool {
var s string
for i := 0; i < 3; i++ {
fmt.Printf("%s ", prompt)
fmt.Scanf("%s", &s)
switch s {
case "y", "Y":
return true
case "n", "N":
return false
case "":
return false
}
fmt.Println("Please press either 'y' or 'n'")
}
return false
}
...@@ -59,30 +59,3 @@ type VersionFileNotFound string ...@@ -59,30 +59,3 @@ type VersionFileNotFound string
func (v VersionFileNotFound) Error() string { func (v VersionFileNotFound) Error() string {
return "no version file in repo at " + string(v) return "no version file in repo at " + string(v)
} }
func TryMigrating(tovers int) error {
if !YesNoPrompt("Run migrations automatically? [y/N]") {
return fmt.Errorf("please run the migrations manually")
}
return RunMigration(tovers)
}
func YesNoPrompt(prompt string) bool {
var s string
for i := 0; i < 3; i++ {
fmt.Printf("%s ", prompt)
fmt.Scanf("%s", &s)
switch s {
case "y", "Y":
return true
case "n", "N":
return false
case "":
return false
}
fmt.Println("Please press either 'y' or 'n'")
}
return false
}
...@@ -27,7 +27,7 @@ test_expect_success "ipfs daemon --migrate=false fails" ' ...@@ -27,7 +27,7 @@ test_expect_success "ipfs daemon --migrate=false fails" '
' '
test_expect_success "output looks good" ' test_expect_success "output looks good" '
grep "ipfs repo needs migration" false_out grep "please run the migrations manually" false_out
' '
test_expect_success "ipfs daemon --migrate=true runs migration" ' test_expect_success "ipfs daemon --migrate=true runs migration" '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论