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

Out of range in ipfs add #2506

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
27 changes: 13 additions & 14 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import (
"os"
gopath "path"

ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
key "github.com/ipfs/go-ipfs/blocks/key"
bserv "github.com/ipfs/go-ipfs/blockservice"
"github.com/ipfs/go-ipfs/exchange/offline"
importer "github.com/ipfs/go-ipfs/importer"
"github.com/ipfs/go-ipfs/importer/chunk"
mfs "github.com/ipfs/go-ipfs/mfs"
Expand Down Expand Up @@ -124,6 +119,7 @@ func (adder Adder) add(reader io.Reader) (*dag.Node, error) {
)
}

// return the final root node of the added data
func (adder *Adder) RootNode() (*dag.Node, error) {
// for memoizing
if adder.root != nil {
Expand All @@ -147,6 +143,7 @@ func (adder *Adder) RootNode() (*dag.Node, error) {
return root, err
}

// Pin or update the pinning of the root node
func (adder *Adder) PinRoot() error {
root, err := adder.RootNode()
if err != nil {
Expand Down Expand Up @@ -183,7 +180,7 @@ func (adder *Adder) Finalize() (*dag.Node, error) {
}

var name string
if !adder.Wrap {
if !adder.Wrap && len(rootNode.Links) == 1 {
name = rootNode.Links[0].Name

dir, ok := adder.mr.GetValue().(*mfs.Directory)
Expand All @@ -210,6 +207,8 @@ func (adder *Adder) Finalize() (*dag.Node, error) {
return root.GetNode()
}

// outputDirs iterate over directories and sends dagnode info
// over the output channel
func (adder *Adder) outputDirs(path string, fs mfs.FSNode) error {
nd, err := fs.GetNode()
if err != nil {
Expand Down Expand Up @@ -262,7 +261,7 @@ func Add(n *core.IpfsNode, r io.Reader) (string, error) {
return k.String(), nil
}

// AddR recursively adds files in |path|.
// AddR recursively adds files in |root|.
func AddR(n *core.IpfsNode, root string) (key string, err error) {
n.Blockstore.PinLock().Unlock()

Expand Down Expand Up @@ -332,6 +331,8 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, *dag.No
return gopath.Join(k.String(), filename), dagnode, nil
}

// insert the node in the mutable fs
// sends dagnode info over the output channel
func (adder *Adder) addNode(node *dag.Node, path string) error {
// patch it into the root
if path == "" {
Expand Down Expand Up @@ -361,6 +362,7 @@ func (adder *Adder) addNode(node *dag.Node, path string) error {
}

// Add the given file while respecting the adder.
// sends dagnode info over the output channel
func (adder *Adder) AddFile(file files.File) error {
adder.unlocker = adder.node.Blockstore.PinLock()
defer func() {
Expand All @@ -370,6 +372,8 @@ func (adder *Adder) AddFile(file files.File) error {
return adder.addFile(file)
}

// store the file/dir in the datastore
// sends dagnode info over the output channel
func (adder *Adder) addFile(file files.File) error {
err := adder.maybePauseForGC()
if err != nil {
Expand Down Expand Up @@ -413,6 +417,8 @@ func (adder *Adder) addFile(file files.File) error {
return adder.addNode(dagnode, file.FileName())
}

// store the directory in the datastore throught the mutable fs
// sends dagnode info over the output channel
func (adder *Adder) addDir(dir files.File) error {
log.Infof("adding directory: %s", dir.FileName())

Expand Down Expand Up @@ -476,13 +482,6 @@ func outputDagnode(out chan interface{}, name string, dn *dag.Node) error {
return nil
}

func NewMemoryDagService() dag.DAGService {
// build mem-datastore for editor's intermediary nodes
bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
bsrv := bserv.New(bs, offline.Exchange(bs))
return dag.NewDAGService(bsrv)
}

// TODO: generalize this to more than unix-fs nodes.
func newDirNode() *dag.Node {
return &dag.Node{Data: unixfs.FolderPBData()}
Expand Down
12 changes: 12 additions & 0 deletions mfs/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// mfs stands for Mutable FileSystem
//
// package mfs implements an in memory model of a mutable ipfs filesystem.
//
// It consists of four main structs:
// 1) The Filesystem
// The filesystem serves as a container and entry point for various mfs filesystems
// 2) Root
// Root represents an individual filesystem mounted within the mfs system as a whole
// 3) Directories
// 4) Files
package mfs
9 changes: 0 additions & 9 deletions mfs/system.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
// package mfs implements an in memory model of a mutable ipfs filesystem.
//
// It consists of four main structs:
// 1) The Filesystem
// The filesystem serves as a container and entry point for various mfs filesystems
// 2) Root
// Root represents an individual filesystem mounted within the mfs system as a whole
// 3) Directories
// 4) Files
package mfs

import (
Expand Down