func WithIpfsAtPathAndPort(t *testing.T, root string, port int, f func(*ipfsutil.Node)) { WithIpfsRepo(t, root, func(path string) { node := ipfsutil.NewWithPort(path, port) f(node) if err := node.Close(); err != nil { t.Errorf("Closing ipfs-daemon failed: %v", err) } }) }
// loadRepository load a brig repository from a given folder. func loadRepository(pwd, folder string) (*Repository, error) { absFolderPath, err := filepath.Abs(folder) if err != nil { return nil, err } brigPath := filepath.Join(absFolderPath, ".brig") cfg, err := config.LoadConfig(filepath.Join(brigPath, "config")) if err != nil { return nil, err } configValues := map[string]string{ "repository.id": "", } for key := range configValues { configValues[key], err = cfg.String(key) if err != nil { return nil, err } } idString, err := cfg.String("repository.id") if err != nil { return nil, err } ID, err := id.Cast(idString) if err != nil { return nil, err } remoteStore, err := NewYAMLRemotes(filepath.Join(brigPath, "remotes.yml")) if err != nil { return nil, err } ipfsSwarmPort, err := cfg.Int("ipfs.swarmport") if err != nil { return nil, err } ipfsLayer := ipfsutil.NewWithPort( filepath.Join(brigPath, "ipfs"), ipfsSwarmPort, ) hash, err := ipfsLayer.Identity() if err != nil { return nil, err } ownStore, err := store.Open(brigPath, id.NewPeer(ID, hash), ipfsLayer) if err != nil { return nil, err } allStores := make(map[id.ID]*store.Store) allStores[ID] = ownStore repo := Repository{ ID: ID, Folder: absFolderPath, Remotes: remoteStore, InternalFolder: brigPath, Config: cfg, OwnStore: ownStore, Password: pwd, IPFS: ipfsLayer, allStores: make(map[id.ID]*store.Store), } return &repo, nil }