@@ -38,7 +38,9 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
38
38
return fmt .Errorf ("downgrade not allowed from %d to %d" , fromVer , targetVer )
39
39
}
40
40
41
- log .Print ("Looking for suitable migration binaries." )
41
+ logger := log .New (os .Stdout , "" , 0 )
42
+
43
+ logger .Print ("Looking for suitable migration binaries." )
42
44
43
45
migrations , binPaths , err := findMigrations (ctx , fromVer , targetVer )
44
46
if err != nil {
@@ -54,17 +56,17 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
54
56
}
55
57
}
56
58
57
- log .Println ("Need" , len (missing ), "migrations, downloading." )
59
+ logger .Println ("Need" , len (missing ), "migrations, downloading." )
58
60
59
61
tmpDir , err := ioutil .TempDir ("" , "migrations" )
60
62
if err != nil {
61
63
return err
62
64
}
63
65
defer os .RemoveAll (tmpDir )
64
66
65
- fetched , err := fetchMigrations (ctx , fetcher , missing , tmpDir )
67
+ fetched , err := fetchMigrations (ctx , fetcher , missing , tmpDir , logger )
66
68
if err != nil {
67
- log .Print ("Failed to download migrations." )
69
+ logger .Print ("Failed to download migrations." )
68
70
return err
69
71
}
70
72
for i := range missing {
@@ -77,13 +79,13 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
77
79
revert = true
78
80
}
79
81
for _ , migration := range migrations {
80
- log .Println ("Running migration" , migration , "..." )
81
- err = runMigration (ctx , binPaths [migration ], ipfsDir , revert )
82
+ logger .Println ("Running migration" , migration , "..." )
83
+ err = runMigration (ctx , binPaths [migration ], ipfsDir , revert , logger )
82
84
if err != nil {
83
85
return fmt .Errorf ("migration %s failed: %s" , migration , err )
84
86
}
85
87
}
86
- log .Printf ("Success: fs-repo migrated to version %d.\n " , targetVer )
88
+ logger .Printf ("Success: fs-repo migrated to version %d.\n " , targetVer )
87
89
88
90
return nil
89
91
}
@@ -142,14 +144,14 @@ func findMigrations(ctx context.Context, from, to int) ([]string, map[string]str
142
144
return migrations , binPaths , nil
143
145
}
144
146
145
- func runMigration (ctx context.Context , binPath , ipfsDir string , revert bool ) error {
147
+ func runMigration (ctx context.Context , binPath , ipfsDir string , revert bool , logger * log. Logger ) error {
146
148
pathArg := fmt .Sprintf ("-path=%s" , ipfsDir )
147
149
var cmd * exec.Cmd
148
150
if revert {
149
- log .Println (" => Running:" , binPath , pathArg , "-verbose=true -revert" )
151
+ logger .Println (" => Running:" , binPath , pathArg , "-verbose=true -revert" )
150
152
cmd = exec .CommandContext (ctx , binPath , pathArg , "-verbose=true" , "-revert" )
151
153
} else {
152
- log .Println (" => Running:" , binPath , pathArg , "-verbose=true" )
154
+ logger .Println (" => Running:" , binPath , pathArg , "-verbose=true" )
153
155
cmd = exec .CommandContext (ctx , binPath , pathArg , "-verbose=true" )
154
156
}
155
157
cmd .Stdout = os .Stdout
@@ -159,7 +161,7 @@ func runMigration(ctx context.Context, binPath, ipfsDir string, revert bool) err
159
161
160
162
// fetchMigrations downloads the requested migrations, and returns a slice with
161
163
// the paths of each binary, in the same order specified by needed.
162
- func fetchMigrations (ctx context.Context , fetcher Fetcher , needed []string , destDir string ) ([]string , error ) {
164
+ func fetchMigrations (ctx context.Context , fetcher Fetcher , needed []string , destDir string , logger * log. Logger ) ([]string , error ) {
163
165
osv , err := osWithVariant ()
164
166
if err != nil {
165
167
return nil , err
@@ -173,21 +175,21 @@ func fetchMigrations(ctx context.Context, fetcher Fetcher, needed []string, dest
173
175
bins := make ([]string , len (needed ))
174
176
// Download and unpack all requested migrations concurrently.
175
177
for i , name := range needed {
176
- log .Printf ("Downloading migration: %s..." , name )
178
+ logger .Printf ("Downloading migration: %s..." , name )
177
179
go func (i int , name string ) {
178
180
defer wg .Done ()
179
181
dist := path .Join (distMigsRoot , name )
180
182
ver , err := LatestDistVersion (ctx , fetcher , dist , false )
181
183
if err != nil {
182
- log .Printf ("could not get latest version of migration %s: %s" , name , err )
184
+ logger .Printf ("could not get latest version of migration %s: %s" , name , err )
183
185
return
184
186
}
185
187
loc , err := FetchBinary (ctx , fetcher , dist , ver , name , destDir )
186
188
if err != nil {
187
- log .Printf ("could not download %s: %s" , name , err )
189
+ logger .Printf ("could not download %s: %s" , name , err )
188
190
return
189
191
}
190
- log .Printf ("Downloaded and unpacked migration: %s (%s)" , loc , ver )
192
+ logger .Printf ("Downloaded and unpacked migration: %s (%s)" , loc , ver )
191
193
bins [i ] = loc
192
194
}(i , name )
193
195
}
0 commit comments