@@ -16,6 +16,7 @@ import (
16
16
"github.com/ipfs/go-ipfs/core/coreapi"
17
17
"github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
18
18
"github.com/ipfs/go-ipfs/repo/fsrepo/migrations/ipfsfetcher"
19
+ coreiface "github.com/ipfs/interface-go-ipfs-core"
19
20
"github.com/ipfs/interface-go-ipfs-core/options"
20
21
ipath "github.com/ipfs/interface-go-ipfs-core/path"
21
22
"github.com/libp2p/go-libp2p-core/peer"
@@ -174,9 +175,9 @@ func addMigrationPaths(ctx context.Context, node *core.IpfsNode, peerInfo peer.A
174
175
175
176
// Connect to temp node
176
177
if err := ipfs .Swarm ().Connect (ctx , peerInfo ); err != nil {
177
- return fmt .Errorf ("cound not connec to migration peer %q: %s" , peerInfo .ID , err )
178
+ return fmt .Errorf ("could not connect to migration peer %q: %s" , peerInfo .ID , err )
178
179
}
179
- fmt .Printf ("conneced to migration peer %q\n " , peerInfo )
180
+ fmt .Printf ("connected to migration peer %q\n " , peerInfo )
180
181
181
182
if pin {
182
183
pinApi := ipfs .Pin ()
@@ -194,23 +195,37 @@ func addMigrationPaths(ctx context.Context, node *core.IpfsNode, peerInfo peer.A
194
195
195
196
// Add migration files
196
197
for _ , ipfsPath := range paths {
197
- nd , err := ufs . Get (ctx , ipfsPath )
198
+ err = ipfsGet (ctx , ufs , ipfsPath )
198
199
if err != nil {
199
200
return err
200
201
}
202
+ }
201
203
202
- fnd , ok := nd .(files. File )
203
- if ! ok {
204
- return fmt . Errorf ( "not a file node: %q" , ipfsPath )
205
- }
206
- io . Copy ( ioutil . Discard , fnd )
207
- nd . Close ()
208
- fmt . Printf ( "Added migration file: %q \n " , ipfsPath )
204
+ return nil
205
+ }
206
+
207
+ func ipfsGet ( ctx context. Context , ufs coreiface. UnixfsAPI , ipfsPath ipath. Path ) error {
208
+ nd , err := ufs . Get ( ctx , ipfsPath )
209
+ if err != nil {
210
+ return err
209
211
}
212
+ defer nd .Close ()
210
213
214
+ fnd , ok := nd .(files.File )
215
+ if ! ok {
216
+ return fmt .Errorf ("not a file node: %q" , ipfsPath )
217
+ }
218
+ _ , err = io .Copy (ioutil .Discard , fnd )
219
+ if err != nil {
220
+ return fmt .Errorf ("could not read migration: %w" , err )
221
+ }
222
+ fmt .Printf ("Added migration file: %q\n " , ipfsPath )
211
223
return nil
212
224
}
213
225
226
+ // parsePeers parses multiaddr strings in the form:
227
+ // /<ip-proto>/<ip-addr>/<transport>/<port>/p2p/<node-id>,..
228
+ // and parses them into a list of peer.AddrInfo, in no particular order
214
229
func parsePeers (migrationPeers string ) ([]peer.AddrInfo , error ) {
215
230
var peers []string
216
231
for _ , p := range strings .Split (migrationPeers , "," ) {
0 commit comments