diff --git a/assets/assets.go b/assets/assets.go index 8f6a8521fb5..a98b83f22f4 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -80,11 +80,6 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) { return nil, err } - dcid, err := nd.DAG.Add(dir) - if err != nil { - return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err) - } - if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil { return nil, fmt.Errorf("assets: Pinning on init-docu failed: %s", err) } @@ -93,5 +88,5 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) { return nil, fmt.Errorf("assets: Pinning flush failed: %s", err) } - return dcid, nil + return dir.Cid(), nil } diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index ed95a5225ba..b45101e5819 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -260,5 +260,5 @@ func initializeIpnsKeyspace(repoRoot string) error { return err } - return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey) + return namesys.InitializeKeyspace(ctx, nd.Namesys, nd.Pinning, nd.PrivateKey) } diff --git a/core/corerepo/pinning.go b/core/corerepo/pinning.go index e10632fe6f7..f00fa239293 100644 --- a/core/corerepo/pinning.go +++ b/core/corerepo/pinning.go @@ -22,18 +22,17 @@ import ( uio "github.com/ipfs/go-ipfs/unixfs/io" cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" - node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" ) func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) { - dagnodes := make([]node.Node, 0) + out := make([]*cid.Cid, len(paths)) r := &path.Resolver{ DAG: n.DAG, ResolveOnce: uio.ResolveUnixfsOnce, } - for _, fpath := range paths { + for i, fpath := range paths { p, err := path.ParsePath(fpath) if err != nil { return nil, err @@ -43,20 +42,11 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) if err != nil { return nil, fmt.Errorf("pin: %s", err) } - dagnodes = append(dagnodes, dagnode) - } - - var out []*cid.Cid - for _, dagnode := range dagnodes { - c := dagnode.Cid() - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - err := n.Pinning.Pin(ctx, dagnode, recursive) + err = n.Pinning.Pin(ctx, dagnode, recursive) if err != nil { return nil, fmt.Errorf("pin: %s", err) } - out = append(out, c) + out[i] = dagnode.Cid() } err := n.Pinning.Flush() @@ -68,14 +58,14 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) } func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) { - var unpinned []*cid.Cid + unpinned := make([]*cid.Cid, len(paths)) r := &path.Resolver{ DAG: n.DAG, ResolveOnce: uio.ResolveUnixfsOnce, } - for _, p := range paths { + for i, p := range paths { p, err := path.ParsePath(p) if err != nil { return nil, err @@ -86,13 +76,11 @@ func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool return nil, err } - ctx, cancel := context.WithCancel(ctx) - defer cancel() err = n.Pinning.Unpin(ctx, k, recursive) if err != nil { return nil, err } - unpinned = append(unpinned, k) + unpinned[i] = k } err := n.Pinning.Flush() diff --git a/fuse/ipns/common.go b/fuse/ipns/common.go index d0d7ba24707..4c9b0d341e9 100644 --- a/fuse/ipns/common.go +++ b/fuse/ipns/common.go @@ -13,16 +13,12 @@ import ( // InitializeKeyspace sets the ipns record for the given key to // point to an empty directory. func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error { - emptyDir := ft.EmptyDirNode() - nodek, err := n.DAG.Add(emptyDir) - if err != nil { - return err - } - ctx, cancel := context.WithCancel(n.Context()) defer cancel() - err = n.Pinning.Pin(ctx, emptyDir, false) + emptyDir := ft.EmptyDirNode() + + err := n.Pinning.Pin(ctx, emptyDir, false) if err != nil { return err } @@ -34,5 +30,5 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error { pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore()) - return pub.Publish(ctx, key, path.FromCid(nodek)) + return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid())) } diff --git a/namesys/publisher.go b/namesys/publisher.go index 03feb204a6d..e98c2391668 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -7,7 +7,6 @@ import ( "fmt" "time" - dag "github.com/ipfs/go-ipfs/merkledag" pb "github.com/ipfs/go-ipfs/namesys/pb" path "github.com/ipfs/go-ipfs/path" pin "github.com/ipfs/go-ipfs/pin" @@ -321,16 +320,12 @@ func ValidateIpnsRecord(k string, val []byte) error { // InitializeKeyspace sets the ipns record for the given key to // point to an empty directory. // TODO: this doesnt feel like it belongs here -func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, pins pin.Pinner, key ci.PrivKey) error { +func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error { emptyDir := ft.EmptyDirNode() - nodek, err := ds.Add(emptyDir) - if err != nil { - return err - } // pin recursively because this might already be pinned // and doing a direct pin would throw an error in that case - err = pins.Pin(ctx, emptyDir, true) + err := pins.Pin(ctx, emptyDir, true) if err != nil { return err } @@ -340,7 +335,7 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p return err } - return pub.Publish(ctx, key, path.FromCid(nodek)) + return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid())) } func IpnsKeysForID(id peer.ID) (name, ipns string) { diff --git a/pin/pin.go b/pin/pin.go index 4faaea6f754..0e55963b363 100644 --- a/pin/pin.go +++ b/pin/pin.go @@ -172,7 +172,10 @@ func NewPinner(dstore ds.Datastore, serv, internal mdag.DAGService) Pinner { func (p *pinner) Pin(ctx context.Context, node node.Node, recurse bool) error { p.lock.Lock() defer p.lock.Unlock() - c := node.Cid() + c, err := p.dserv.Add(node) + if err != nil { + return err + } if recurse { if p.recursePin.Has(c) {