Skip to content

Commit

Permalink
cmd: fix repo premature close
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 6, 2023
1 parent f5d0232 commit 126525c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 2 additions & 7 deletions cmd/siapfsd/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/coreapi"
"github.com/ipfs/kubo/plugin/loader"
"github.com/ipfs/kubo/repo"
"github.com/ipfs/kubo/repo/fsrepo"
"go.sia.tech/renterd/worker"
"go.sia.tech/siapfs/ipfs/blockstore"
Expand Down Expand Up @@ -52,13 +53,7 @@ func initRepo(repoPath string) error {
return fsrepo.Init(repoPath, conf)
}

func createNode(ctx context.Context, repoPath string, db *badger.Store, renterd *worker.Client, bucket string) (iface.CoreAPI, *core.IpfsNode, error) {
r, err := fsrepo.Open(repoPath)
if err != nil {
return nil, nil, fmt.Errorf("failed to open repo: %w", err)
}
defer r.Close()

func createNode(ctx context.Context, r repo.Repo, db *badger.Store, renterd *worker.Client, bucket string) (iface.CoreAPI, *core.IpfsNode, error) {
node, err := core.NewNode(ctx, &core.BuildCfg{
Online: true,
Repo: r,
Expand Down
10 changes: 9 additions & 1 deletion cmd/siapfsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"syscall"

"github.com/ipfs/kubo/repo/fsrepo"
"go.sia.tech/jape"
"go.sia.tech/renterd/worker"
"go.sia.tech/siapfs/build"
Expand Down Expand Up @@ -111,7 +112,14 @@ func main() {
defer ds.Close()

client := worker.NewClient(cfg.Renterd.Address, cfg.Renterd.Password)
coreAPI, node, err := createNode(ctx, ipfsPath, ds, client, cfg.Renterd.Bucket)

r, err := fsrepo.Open(ipfsPath)
if err != nil {
log.Fatal("failed to open repo", zap.Error(err))
}
defer r.Close()

coreAPI, node, err := createNode(ctx, r, ds, client, cfg.Renterd.Bucket)
if err != nil {
log.Fatal("failed to start ipfs node", zap.Error(err))
}
Expand Down

0 comments on commit 126525c

Please sign in to comment.