@cryptotaxi247 / kubo / commits / b213d6909

fsrepo: improve migrations copy

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Aug 31, 2016 at 02:44 UTC b213d69099a5a115e31af0143066f1b8e7cb453a
2 files changed +21 -15
cmd/ipfs/daemon.go
+9 -3
@@ -226,19 +226,25 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
226 return
227 case fsrepo.ErrNeedMigration:
228 domigrate, found, _ := req.Option(migrateKwd).Bool()
229 - fmt.Println("Found old repo version, migrations need to be run.")
229 + fmt.Println("Found outdated fs-repo, migrations need to be run.")
230
231 if !found {
232 - domigrate = YesNoPrompt("Run migrations automatically? [y/N]")
232 + domigrate = YesNoPrompt("Run migrations now? [y/N]")
233 }
234
235 if !domigrate {
236 - res.SetError(fmt.Errorf("please run the migrations manually"), cmds.ErrNormal)
236 + fmt.Println("Not running migrations of fs-repo now.")
237 + fmt.Println("Please get fs-repo-migrations from https://dist.ipfs.io")
238 + res.SetError(fmt.Errorf("fs-repo requires migration"), cmds.ErrNormal)
239 return
240 }
241
242 err = migrate.RunMigration(fsrepo.RepoVersion)
243 if err != nil {
244 + fmt.Println("The migrations of fs-repo failed:")
245 + fmt.Printf(" %s\n", err)
246 + fmt.Println("If you think this is a bug, please file an issue and include this whole log output.")
247 + fmt.Println(" https://github.com/ipfs/fs-repo-migrations")
248 res.SetError(err, cmds.ErrNormal)
249 return
250 }
repo/fsrepo/migrations/migrations.go
+12 -12
@@ -37,7 +37,7 @@ func migrationsBinName() string {
37 func RunMigration(newv int) error {
38 migrateBin := migrationsBinName()
39
40 - fmt.Println(" => checking for migrations binary...")
40 + fmt.Println(" => Looking for suitable fs-repo-migrations binary.")
41
42 var err error
43 migrateBin, err = exec.LookPath(migrateBin)
@@ -47,15 +47,17 @@ func RunMigration(newv int) error {
47 }
48
49 if err != nil {
50 - fmt.Println(" => usable migrations not found on system, fetching...")
50 + fmt.Println(" => None found, downloading.")
51 +
52 loc, err := GetMigrations()
53 if err != nil {
54 + fmt.Println(" => Failed to download fs-repo-migrations.")
55 return err
56 }
57
58 err = verifyMigrationSupportsVersion(loc, newv)
59 if err != nil {
58 - return fmt.Errorf("no migration binary found that supports version %d - %s", newv, err)
60 + return fmt.Errorf("no fs-repo-migration binary found for version %d: %s", newv, err)
61 }
62
63 migrateBin = loc
@@ -65,14 +67,15 @@ func RunMigration(newv int) error {
67 cmd.Stdout = os.Stdout
68 cmd.Stderr = os.Stderr
69
68 - fmt.Printf(" => running migration: '%s -to %d -y'\n\n", migrateBin, newv)
70 + fmt.Printf(" => Running: %s -to %d -y\n", migrateBin, newv)
71
72 err = cmd.Run()
73 if err != nil {
74 + fmt.Printf(" => Failed: %s -to %d -y\n", migrateBin, newv)
75 return fmt.Errorf("migration failed: %s", err)
76 }
77
75 - fmt.Println(" => migrations binary completed successfully")
78 + fmt.Printf(" => Success: fs-repo has been migrated to version %d.\n", newv)
79
80 return nil
81 }
@@ -80,21 +83,19 @@ func RunMigration(newv int) error {
83 func GetMigrations() (string, error) {
84 latest, err := GetLatestVersion(DistPath, migrations)
85 if err != nil {
83 - return "", fmt.Errorf("getting latest version of fs-repo-migrations: %s", err)
86 + return "", fmt.Errorf("failed to find latest fs-repo-migrations: %s", err)
87 }
88
89 dir, err := ioutil.TempDir("", "go-ipfs-migrate")
90 if err != nil {
88 - return "", fmt.Errorf("tempdir: %s", err)
91 + return "", fmt.Errorf("failed to create fs-repo-migrations tempdir: %s", err)
92 }
93
94 out := filepath.Join(dir, migrationsBinName())
95
96 err = GetBinaryForVersion(migrations, migrations, DistPath, latest, out)
97 if err != nil {
95 - fmt.Printf(" => error getting migrations binary: %s\n", err)
96 - fmt.Println(" => could not find or install fs-repo-migrations, please manually install it")
97 - return "", fmt.Errorf("failed to find migrations binary")
98 + return "", fmt.Errorf("failed to download latest fs-repo-migrations: %s", err)
99 }
100
101 err = os.Chmod(out, 0755)
@@ -184,7 +185,6 @@ func httpGet(url string) (*http.Response, error) {
185 }
186
187 func httpFetch(url string) (io.ReadCloser, error) {
187 - fmt.Printf("fetching url: %s\n", url)
188 resp, err := httpGet(url)
189 if err != nil {
190 return nil, err
@@ -196,7 +196,7 @@ func httpFetch(url string) (io.ReadCloser, error) {
196 return nil, fmt.Errorf("error reading error body: %s", err)
197 }
198
199 - return nil, fmt.Errorf("%s: %s", resp.Status, string(mes))
199 + return nil, fmt.Errorf("GET %s error: %s: %s", url, resp.Status, string(mes))
200 }
201
202 return resp.Body, nil