mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
move prompt code into daemon.go
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
@ -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 {
|
|||||||
}()
|
}()
|
||||||
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
|
|||||||
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" '
|
|||||||
'
|
'
|
||||||
|
|
||||||
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" '
|
||||||
|
Reference in New Issue
Block a user