From b941f612af8d38d42257cc8b0ade6322ba216852 Mon Sep 17 00:00:00 2001 From: gammazero Date: Fri, 13 Aug 2021 17:08:31 -0700 Subject: [PATCH] Allow repo migrate command to use IPFS for migration download Additional change to remove leftover debug output from ipfsfetcher.go noticed during testing. --- core/commands/repo.go | 26 ++++++++++++++++++- .../migrations/ipfsfetcher/ipfsfetcher.go | 2 -- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/commands/repo.go b/core/commands/repo.go index 7c60ab82c5e8..9f6657316530 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -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" @@ -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:") diff --git a/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go b/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go index 88f07b502ee7..0d1a0c18d0f7 100644 --- a/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go +++ b/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go @@ -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)