Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore copy util #469

Merged
merged 6 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func DefaultNetwork(opts ...NetOption) (NetBoostrapper, error) {
}
fin.Add(pstore)

hostKey, err := getHostKey(config, litestore)
hostKey, err := getIPFSHostKey(config, litestore)
if err != nil {
return nil, fin.Cleanup(err)
}
Expand Down Expand Up @@ -174,12 +174,12 @@ func mongoStore(ctx context.Context, uri, db, collection string, fin *util.Final
return dstore, nil
}

func getHostKey(config NetConfig, store ds.Batching) (crypto.PrivKey, error) {
func getIPFSHostKey(config NetConfig, store ds.Datastore) (crypto.PrivKey, error) {
if len(config.MongoUri) != 0 {
k := ds.NewKey("key")
bytes, err := store.Get(k)
if errors.Is(err, ds.ErrNotFound) {
key, bytes, err := newHostKey()
key, bytes, err := newIPFSHostKey()
if err != nil {
return nil, err
}
Expand All @@ -194,16 +194,16 @@ func getHostKey(config NetConfig, store ds.Batching) (crypto.PrivKey, error) {
} else {
// If a local datastore is used, the key is written to a file
dir := filepath.Join(config.BadgerRepoPath, "ipfslite")
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return nil, err
}
pth := filepath.Join(dir, "key")
_, err := os.Stat(pth)
if os.IsNotExist(err) {
key, bytes, err := newHostKey()
key, bytes, err := newIPFSHostKey()
if err != nil {
return nil, err
}
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return nil, err
}
if err = ioutil.WriteFile(pth, bytes, 0400); err != nil {
return nil, err
}
Expand All @@ -220,7 +220,7 @@ func getHostKey(config NetConfig, store ds.Batching) (crypto.PrivKey, error) {
}
}

func newHostKey() (crypto.PrivKey, []byte, error) {
func newIPFSHostKey() (crypto.PrivKey, []byte, error) {
priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 0)
if err != nil {
return nil, nil, err
Expand Down
127 changes: 0 additions & 127 deletions util/datastore/dscopy/main.go

This file was deleted.

Loading