Commit 675106d7 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi unixfs: rebase fixes for fileAdder.AddAllAndPin

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 374fb00c
......@@ -302,7 +302,7 @@ You can now check what blocks have been created by:
var err error
defer func() { errCh <- err }()
defer close(outChan)
err = fileAdder.AddAllAndPin(req.Files)
_, err = fileAdder.AddAllAndPin(req.Files)
}()
err = res.Emit(outChan)
......
......@@ -68,7 +68,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
//fileAdder.Progress = progress
//fileAdder.Hidden = hidden
//fileAdder.Wrap = wrap
fileAdder.Pin = settings.Pin
fileAdder.Pin = settings.Pin && !settings.OnlyHash
fileAdder.Silent = true
fileAdder.RawLeaves = settings.RawLeaves
//fileAdder.NoCopy = nocopy
......@@ -104,21 +104,11 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
fileAdder.SetMfsRoot(mr)
}
err = fileAdder.AddFile(files.NewReaderFile("", "", r, nil))
nd, err := fileAdder.AddAllAndPin(files.NewReaderFile("", "", r, nil))
if err != nil {
return nil, err
}
nd, err := fileAdder.Finalize()
if err != nil {
return nil, err
}
if settings.Pin {
err = fileAdder.PinRoot()
}
return coreiface.IpfsPath(nd.Cid()), err
return coreiface.IpfsPath(nd.Cid()), nil
}
// Cat returns the data contained by an IPFS or IPNS object(s) at path `p`.
......
......@@ -399,7 +399,7 @@ func (adder *Adder) addNode(node ipld.Node, path string) error {
}
// AddAllAndPin adds the given request's files and pin them.
func (adder *Adder) AddAllAndPin(file files.File) error {
func (adder *Adder) AddAllAndPin(file files.File) (ipld.Node, error) {
if adder.Pin {
adder.unlocker = adder.blockstore.PinLock()
}
......@@ -420,30 +420,30 @@ func (adder *Adder) AddAllAndPin(file files.File) error {
// Finished the list of files.
break
} else if err != nil {
return err
return nil, err
}
if err := adder.addFile(file); err != nil {
return err
return nil, err
}
}
break
default:
if err := adder.addFile(file); err != nil {
return err
return nil, err
}
break
}
// copy intermediary nodes from editor to our actual dagservice
_, err := adder.Finalize()
nd, err := adder.Finalize()
if err != nil {
return err
return nil, err
}
if !adder.Pin {
return nil
return nd, nil
}
return adder.PinRoot()
return nd, adder.PinRoot()
}
func (adder *Adder) addFile(file files.File) error {
......
......@@ -85,7 +85,7 @@ func TestAddGCLive(t *testing.T) {
go func() {
defer close(addDone)
defer close(out)
err := adder.AddAllAndPin(slf)
_, err := adder.AddAllAndPin(slf)
if err != nil {
t.Fatal(err)
......@@ -191,7 +191,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
go func() {
defer close(adder.Out)
err = adder.AddAllAndPin(file)
_, err = adder.AddAllAndPin(file)
if err != nil {
t.Fatal(err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment