migrations

package
v0.0.0-...-b839421 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2021 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Current dirstibution to fetch migrations from
	CurrentIpfsDist = "/ipfs/QmP7tLxzhLU1KauTRX3jkVkF93pCv4skcceyUYMhf4AKJR" // fs-repo-migrations v2.0.2
	// Latest distribution path.  Default for fetchers.
	LatestIpfsDist = "/ipns/dist.ipfs.io"
)

Variables

View Source
var DownloadDirectory string

DownloadDirectory can be set as the location for FetchBinary to save the downloaded archive file in. If not set, then FetchBinary saves the archive in a temporary directory that is removed after the contents of the archive is extracted.

Functions

func CheckIpfsDir

func CheckIpfsDir(dir string) (string, error)

CheckIpfsDir gets the ipfs directory and checks that the directory exists.

func DistVersions

func DistVersions(ctx context.Context, fetcher Fetcher, dist string, sortDesc bool) ([]string, error)

DistVersions returns all versions of the specified distribution, that are available on the distriburion site. List is in ascending order, unless sortDesc is true.

func ExeName

func ExeName(name string) string

func FetchBinary

func FetchBinary(ctx context.Context, fetcher Fetcher, dist, ver, binName, out string) (string, error)

FetchBinary downloads an archive from the distribution site and unpacks it.

The base name of the binary inside the archive may differ from the base archive name. If it does, then specify binName. For example, the following is needed because the archive "go-ipfs_v0.7.0_linux-amd64.tar.gz" contains a binary named "ipfs"

FetchBinary(ctx, fetcher, "go-ipfs", "v0.7.0", "ipfs", tmpDir)

If out is a directory, then the binary is written to that directory with the same name it has inside the archive. Otherwise, the binary file is written to the file named by out.

func GetDistPathEnv

func GetDistPathEnv(distPath string) string

GetDistPathEnv returns the IPFS path to the distribution site, using the value of environ variable specified by envIpfsDistPath. If the environ variable is not set, then returns the provided distPath, and if that is not set then returns the IPNS path.

To get the IPFS path of the latest distribution, if not overriddin by the environ variable: GetDistPathEnv(CurrentIpfsDist)

func IpfsDir

func IpfsDir(dir string) (string, error)

IpfsDir returns the path of the ipfs directory. If dir specified, then returns the expanded version dir. If dir is "", then return the directory set by IPFS_PATH, or if IPFS_PATH is not set, then return the default location in the home directory.

func LatestDistVersion

func LatestDistVersion(ctx context.Context, fetcher Fetcher, dist string, stableOnly bool) (string, error)

LatestDistVersion returns the latest version, of the specified distribution, that is available on the distribution site.

func NeedMigration

func NeedMigration(target int) (bool, error)

func NewLimitReadCloser

func NewLimitReadCloser(rc io.ReadCloser, limit int64) io.ReadCloser

NewLimitReadCloser returns a new io.ReadCloser with the reader wrappen in a io.LimitedReader limited to reading the amount specified.

func ReadMigrationConfig

func ReadMigrationConfig(repoRoot string) (*config.Migration, error)

ReadMigrationConfig reads the Migration section of the IPFS config, avoiding reading anything other than the Migration section. That way, we're free to make arbitrary changes to all _other_ sections in migrations.

func RepoVersion

func RepoVersion(ipfsDir string) (int, error)

RepoVersion returns the version of the repo in the ipfs directory. If the ipfs directory is not specified then the default location is used.

func RunMigration

func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir string, allowDowngrade bool) error

RunMigration finds, downloads, and runs the individual migrations needed to migrate the repo from its current version to the target version.

func WriteRepoVersion

func WriteRepoVersion(ipfsDir string, version int) error

WriteRepoVersion writes the specified repo version to the repo located in ipfsDir. If ipfsDir is not specified, then the default location is used.

Types

type Fetcher

type Fetcher interface {
	// Fetch attempts to fetch the file at the given ipfs path.
	// Returns io.ReadCloser on success, which caller must close.
	Fetch(ctx context.Context, filePath string) (io.ReadCloser, error)
	// Close performs any cleanup after the fetcher is not longer needed.
	Close() error
}

func GetMigrationFetcher

func GetMigrationFetcher(downloadSources []string, distPath string, newIpfsFetcher func(string) Fetcher) (Fetcher, error)

GetMigrationFetcher creates one or more fetchers according to downloadSources,

func NewMultiFetcher

func NewMultiFetcher(f ...Fetcher) Fetcher

NewMultiFetcher creates a MultiFetcher with the given Fetchers. The Fetchers are tried in order ther passed to this function.

type HttpFetcher

type HttpFetcher struct {
	// contains filtered or unexported fields
}

HttpFetcher fetches files over HTTP

func NewHttpFetcher

func NewHttpFetcher(distPath, gateway, userAgent string, fetchLimit int64) *HttpFetcher

NewHttpFetcher creates a new HttpFetcher

Specifying "" for distPath sets the default IPNS path. Specifying "" for gateway sets the default. Specifying 0 for fetchLimit sets the default, -1 means no limit.

func (*HttpFetcher) Close

func (f *HttpFetcher) Close() error

func (*HttpFetcher) Fetch

func (f *HttpFetcher) Fetch(ctx context.Context, filePath string) (io.ReadCloser, error)

Fetch attempts to fetch the file at the given path, from the distribution site configured for this HttpFetcher. Returns io.ReadCloser on success, which caller must close.

type MultiFetcher

type MultiFetcher struct {
	// contains filtered or unexported fields
}

MultiFetcher holds multiple Fetchers and provides a Fetch that tries each until one succeeds.

func (*MultiFetcher) Close

func (f *MultiFetcher) Close() error

func (*MultiFetcher) Fetch

func (f *MultiFetcher) Fetch(ctx context.Context, ipfsPath string) (io.ReadCloser, error)

Fetch attempts to fetch the file at each of its fetchers until one succeeds. Returns io.ReadCloser on success, which caller must close.

func (*MultiFetcher) Fetchers

func (f *MultiFetcher) Fetchers() []Fetcher

func (*MultiFetcher) Len

func (f *MultiFetcher) Len() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL