示例#1
0
文件: repo.go 项目: disorganizer/brig
func (rp *Repository) Peer() id.Peer {
	hash, err := rp.IPFS.Identity()
	if err != nil {
		log.Warningf("Cannot retrieve ipfs id: %v", err)
		hash = ""
	}
	return id.NewPeer(rp.ID, hash)

}
示例#2
0
func withStore(t *testing.T, ID id.ID, IPFS *ipfsutil.Node, fn func(st *store.Store)) {
	tempDir, err := ioutil.TempDir("", "brig-store-")
	if err != nil {
		t.Fatalf("Could not create temp dir `%s`: %v", tempDir, err)
		return
	}

	defer testutil.Remover(t, tempDir)

	st, err := store.Open(tempDir, id.NewPeer(ID, "QmIMACOW"), IPFS)
	if err != nil {
		t.Fatalf("Could not create store: %v", err)
		return
	}

	fn(st)
}
示例#3
0
// TODO: make the with functions globally available.
func withStore(t *testing.T, ID id.ID, IPFS *ipfsutil.Node, fn func(st *Store)) {
	tempDir, err := ioutil.TempDir("", "brig-store-")
	if err != nil {
		t.Fatalf("Could not create temp dir `%s`: %v", tempDir, err)
		return
	}

	defer testutil.Remover(t, tempDir)

	st, err := Open(tempDir, id.NewPeer(ID, "QmW2jc7k5Ug987QEkUx6tJUTdZov7io39MDCiKKp2f57mD"), IPFS)
	if err != nil {
		t.Fatalf("Could not create store: %v", err)
		return
	}

	fn(st)
}
示例#4
0
func withEmptyStore(t *testing.T, f func(*store.Store)) {
	ipfsPath := filepath.Join(TestPath, "ipfs")

	testwith.WithIpfsAtPath(t, ipfsPath, func(node *ipfsutil.Node) {
		if err := os.MkdirAll(TestPath, 0744); err != nil {
			t.Errorf("Could not create store dir at %s: %v", TestPath, err)
			return
		}

		defer func() {
			if err := os.RemoveAll(TestPath); err != nil {
				t.Errorf("Could not remove temp dir for empty store.")
				return
			}
		}()

		// We need the filesystem for ipfs here:
		peer := id.NewPeer(
			id.ID("[email protected]/desktop"),
			store.EmptyHash.B58String(),
		)

		st, err := store.Open(TestPath, peer, node)
		if err != nil {
			t.Errorf("Could not open empty store at %s: %v", TestPath, err)
			return
		}

		f(st)

		if err := st.Close(); err != nil {
			t.Errorf("Unable to close empty store: %v", err)
			return
		}
	})
}
示例#5
0
文件: open.go 项目: disorganizer/brig
// 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
}