Skip to content

Commit

Permalink
Allow repo migrate command to use IPFS for migration download
Browse files Browse the repository at this point in the history
Additional change to remove leftover debug output from ipfsfetcher.go noticed during testing.
  • Loading branch information
gammazero committed Sep 3, 2021
1 parent 0547491 commit 59a418b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 25 additions & 1 deletion core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
"github.com/ipfs/go-ipfs/repo/fsrepo/migrations/ipfsfetcher"

humanize "github.com/dustin/go-humanize"
cid "github.com/ipfs/go-cid"
Expand Down Expand Up @@ -400,8 +401,31 @@ var repoMigrateCmd = &cmds.Command{

fmt.Println("Found outdated fs-repo, starting migration.")

// Read Migration section of IPFS config
migrationCfg, err := migrate.ReadMigrationConfig(cctx.ConfigRoot)
if err != nil {
return err
}

// Define function to create IPFS fetcher. Do not supply an
// already-constructed IPFS fetcher, because this may be expensive and
// not needed according to migration config. Instead, supply a function
// to construct the particular IPFS fetcher implementation used here,
// which is called only if an IPFS fetcher is needed.
newIpfsFetcher := func(distPath string) migrate.Fetcher {
return ipfsfetcher.NewIpfsFetcher(distPath, 0, &cctx.ConfigRoot)
}

// Fetch migrations from current distribution, or location from environ
fetcher := migrate.NewHttpFetcher(migrate.GetDistPathEnv(migrate.CurrentIpfsDist), "", "go-ipfs", 0)
fetchDistPath := migrate.GetDistPathEnv(migrate.CurrentIpfsDist)

// Create fetchers according to migrationCfg.DownloadSources
fetcher, err := migrate.GetMigrationFetcher(migrationCfg.DownloadSources, fetchDistPath, newIpfsFetcher)
if err != nil {
return err
}
defer fetcher.Close()

err = migrate.RunMigration(cctx.Context(), fetcher, fsrepo.RepoVersion, "", allowDowngrade)
if err != nil {
fmt.Println("The migrations of fs-repo failed:")
Expand Down
2 changes: 0 additions & 2 deletions repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ func (f *IpfsFetcher) startTempNode(ctx context.Context) error {
cancel()
// Wait until ipfs is stopped
<-node.Context().Done()

fmt.Println("migration peer", node.Identity, "shutdown")
}

addrs, err := ipfs.Swarm().LocalAddrs(ctx)
Expand Down

0 comments on commit 59a418b

Please sign in to comment.