Skip to content

Commit

Permalink
adder: split into base and dir job
Browse files Browse the repository at this point in the history
This way, we can entirely avoid MFS when adding single files.

This patch also changes how Pin/OnlyHash works. Instead of having a Pin option,
just construct the adder with a `nil` pinner to not pin. Likewise, we handle
"only hash" by passing a nil dagservice.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Mar 23, 2019
1 parent fda7a6a commit a4e842f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 136 deletions.
39 changes: 17 additions & 22 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/filestore"
pin "github.com/ipfs/go-ipfs/pin"

"github.com/ipfs/go-ipfs/core/coreunix"

Expand Down Expand Up @@ -51,29 +51,25 @@ func (api *UnixfsAPI) Add(ctx context.Context, file files.Node, opts ...options.
return nil, filestore.ErrFilestoreNotEnabled
}

addblockstore := api.blockstore
if !(settings.FsCache || settings.NoCopy) {
addblockstore = bstore.NewGCBlockstore(api.baseBlocks, api.blockstore)
}
exch := api.exchange
pinning := api.pinning
var (
pinning pin.Pinner
dserv ipld.DAGService
addblockstore bstore.GCBlockstore
)

if settings.OnlyHash {
nilnode, err := core.NewNode(ctx, &core.BuildCfg{
//TODO: need this to be true or all files
// hashed will be stored in memory!
NilRepo: true,
})
if err != nil {
return nil, err
if !settings.OnlyHash {
addblockstore = api.blockstore
if !(settings.FsCache || settings.NoCopy) {
// XXX: Why do we need this?
addblockstore = bstore.NewGCBlockstore(api.baseBlocks, addblockstore)
}
if settings.Pin {
pinning = api.pinning
}
addblockstore = nilnode.Blockstore
exch = nilnode.Exchange
pinning = nilnode.Pinning
}

bserv := blockservice.New(addblockstore, exch) // hash security 001
dserv := dag.NewDAGService(bserv)
bserv := blockservice.New(addblockstore, api.exchange) // hash security 001
dserv = dag.NewDAGService(bserv)
}

fileAdder, err := coreunix.NewAdder(pinning, addblockstore, dserv)
if err != nil {
Expand All @@ -85,7 +81,6 @@ func (api *UnixfsAPI) Add(ctx context.Context, file files.Node, opts ...options.
fileAdder.Out = settings.Events
fileAdder.Progress = settings.Progress
}
fileAdder.Pin = settings.Pin && !settings.OnlyHash
fileAdder.Silent = settings.Silent
fileAdder.RawLeaves = settings.RawLeaves
fileAdder.NoCopy = settings.NoCopy
Expand Down
Loading

0 comments on commit a4e842f

Please sign in to comment.