提交 b213d690 作者: Lars Gierth 提交者: Jeromy

fsrepo: improve migrations copy

License: MIT
Signed-off-by: 's avatarLars Gierth <larsg@systemli.org>
上级 686882bd
...@@ -226,19 +226,25 @@ func daemonFunc(req cmds.Request, res cmds.Response) { ...@@ -226,19 +226,25 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
return return
case fsrepo.ErrNeedMigration: case fsrepo.ErrNeedMigration:
domigrate, found, _ := req.Option(migrateKwd).Bool() domigrate, found, _ := req.Option(migrateKwd).Bool()
fmt.Println("Found old repo version, migrations need to be run.") fmt.Println("Found outdated fs-repo, migrations need to be run.")
if !found { if !found {
domigrate = YesNoPrompt("Run migrations automatically? [y/N]") domigrate = YesNoPrompt("Run migrations now? [y/N]")
} }
if !domigrate { if !domigrate {
res.SetError(fmt.Errorf("please run the migrations manually"), cmds.ErrNormal) fmt.Println("Not running migrations of fs-repo now.")
fmt.Println("Please get fs-repo-migrations from https://dist.ipfs.io")
res.SetError(fmt.Errorf("fs-repo requires migration"), cmds.ErrNormal)
return return
} }
err = migrate.RunMigration(fsrepo.RepoVersion) err = migrate.RunMigration(fsrepo.RepoVersion)
if err != nil { if err != nil {
fmt.Println("The migrations of fs-repo failed:")
fmt.Printf(" %s\n", err)
fmt.Println("If you think this is a bug, please file an issue and include this whole log output.")
fmt.Println(" https://github.com/ipfs/fs-repo-migrations")
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
} }
......
...@@ -37,7 +37,7 @@ func migrationsBinName() string { ...@@ -37,7 +37,7 @@ func migrationsBinName() string {
func RunMigration(newv int) error { func RunMigration(newv int) error {
migrateBin := migrationsBinName() migrateBin := migrationsBinName()
fmt.Println(" => checking for migrations binary...") fmt.Println(" => Looking for suitable fs-repo-migrations binary.")
var err error var err error
migrateBin, err = exec.LookPath(migrateBin) migrateBin, err = exec.LookPath(migrateBin)
...@@ -47,15 +47,17 @@ func RunMigration(newv int) error { ...@@ -47,15 +47,17 @@ func RunMigration(newv int) error {
} }
if err != nil { if err != nil {
fmt.Println(" => usable migrations not found on system, fetching...") fmt.Println(" => None found, downloading.")
loc, err := GetMigrations() loc, err := GetMigrations()
if err != nil { if err != nil {
fmt.Println(" => Failed to download fs-repo-migrations.")
return err return err
} }
err = verifyMigrationSupportsVersion(loc, newv) err = verifyMigrationSupportsVersion(loc, newv)
if err != nil { if err != nil {
return fmt.Errorf("no migration binary found that supports version %d - %s", newv, err) return fmt.Errorf("no fs-repo-migration binary found for version %d: %s", newv, err)
} }
migrateBin = loc migrateBin = loc
...@@ -65,14 +67,15 @@ func RunMigration(newv int) error { ...@@ -65,14 +67,15 @@ func RunMigration(newv int) error {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
fmt.Printf(" => running migration: '%s -to %d -y'\n\n", migrateBin, newv) fmt.Printf(" => Running: %s -to %d -y\n", migrateBin, newv)
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
fmt.Printf(" => Failed: %s -to %d -y\n", migrateBin, newv)
return fmt.Errorf("migration failed: %s", err) return fmt.Errorf("migration failed: %s", err)
} }
fmt.Println(" => migrations binary completed successfully") fmt.Printf(" => Success: fs-repo has been migrated to version %d.\n", newv)
return nil return nil
} }
...@@ -80,21 +83,19 @@ func RunMigration(newv int) error { ...@@ -80,21 +83,19 @@ func RunMigration(newv int) error {
func GetMigrations() (string, error) { func GetMigrations() (string, error) {
latest, err := GetLatestVersion(DistPath, migrations) latest, err := GetLatestVersion(DistPath, migrations)
if err != nil { if err != nil {
return "", fmt.Errorf("getting latest version of fs-repo-migrations: %s", err) return "", fmt.Errorf("failed to find latest fs-repo-migrations: %s", err)
} }
dir, err := ioutil.TempDir("", "go-ipfs-migrate") dir, err := ioutil.TempDir("", "go-ipfs-migrate")
if err != nil { if err != nil {
return "", fmt.Errorf("tempdir: %s", err) return "", fmt.Errorf("failed to create fs-repo-migrations tempdir: %s", err)
} }
out := filepath.Join(dir, migrationsBinName()) out := filepath.Join(dir, migrationsBinName())
err = GetBinaryForVersion(migrations, migrations, DistPath, latest, out) err = GetBinaryForVersion(migrations, migrations, DistPath, latest, out)
if err != nil { if err != nil {
fmt.Printf(" => error getting migrations binary: %s\n", err) return "", fmt.Errorf("failed to download latest fs-repo-migrations: %s", err)
fmt.Println(" => could not find or install fs-repo-migrations, please manually install it")
return "", fmt.Errorf("failed to find migrations binary")
} }
err = os.Chmod(out, 0755) err = os.Chmod(out, 0755)
...@@ -184,7 +185,6 @@ func httpGet(url string) (*http.Response, error) { ...@@ -184,7 +185,6 @@ func httpGet(url string) (*http.Response, error) {
} }
func httpFetch(url string) (io.ReadCloser, error) { func httpFetch(url string) (io.ReadCloser, error) {
fmt.Printf("fetching url: %s\n", url)
resp, err := httpGet(url) resp, err := httpGet(url)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -196,7 +196,7 @@ func httpFetch(url string) (io.ReadCloser, error) { ...@@ -196,7 +196,7 @@ func httpFetch(url string) (io.ReadCloser, error) {
return nil, fmt.Errorf("error reading error body: %s", err) return nil, fmt.Errorf("error reading error body: %s", err)
} }
return nil, fmt.Errorf("%s: %s", resp.Status, string(mes)) return nil, fmt.Errorf("GET %s error: %s: %s", url, resp.Status, string(mes))
} }
return resp.Body, nil return resp.Body, nil
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论