Skip to content

Commit

Permalink
WIP almost working ipfs add
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Mar 10, 2019
1 parent 7b57c58 commit 3b2d568
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 18 additions & 2 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ You can now check what blocks have been created by:

events := make(chan interface{}, adderOutChanSize)

var toadd files.Node = req.Files
addName := ""
if !wrap {
it := req.Files.Entries()
if !it.Next() {
err := it.Err()
if err == nil {
return fmt.Errorf("expected a file argument")
}
return err
}

addName = it.Name()
toadd = it.Node()
}

opts := []options.UnixfsAddOption{
options.Unixfs.Hash(hashFunCode),

Expand All @@ -198,13 +214,13 @@ You can now check what blocks have been created by:
options.Unixfs.FsCache(fscache),
options.Unixfs.Nocopy(nocopy),

options.Unixfs.Wrap(wrap),
options.Unixfs.Hidden(hidden),
options.Unixfs.StdinName(pathName),

options.Unixfs.Progress(progress),
options.Unixfs.Silent(silent),
options.Unixfs.Events(events),
options.Unixfs.BaseName(addName),
}

if cidVerSet {
Expand All @@ -224,7 +240,7 @@ You can now check what blocks have been created by:
var err error
defer func() { errCh <- err }()
defer close(events)
_, err = api.Unixfs().Add(req.Context, req.Files, opts...)
_, err = api.Unixfs().Add(req.Context, toadd, opts...)
}()

for event := range events {
Expand Down
1 change: 1 addition & 0 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
fileAdder.RawLeaves = settings.RawLeaves
fileAdder.NoCopy = settings.NoCopy
fileAdder.Name = settings.StdinName
fileAdder.BaseName = settings.BaseName
fileAdder.CidBuilder = prefix
fileAdder.TopHidden = settings.TopHidden

Expand Down
6 changes: 5 additions & 1 deletion core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Adder struct {
Silent bool
Wrap bool
Name string
BaseName string
NoCopy bool
Chunker string
root ipld.Node
Expand Down Expand Up @@ -230,6 +231,9 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {

func (adder *Adder) addNode(node ipld.Node, path string) error {
// patch it into the root
if adder.BaseName != "" {
path = gopath.Join(adder.BaseName, path)
}
if path == "" {
path = node.Cid().String()
}
Expand Down Expand Up @@ -351,7 +355,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
return nil, err
}

if err := outputDagnode(adder.Out, "", nd); err != nil {
if err := outputDagnode(adder.Out, adder.BaseName, nd); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit 3b2d568

Please sign in to comment.