diff --git a/core/coreunix/add.go b/core/coreunix/add.go index d9160c6b0..378b70c1e 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -201,7 +201,8 @@ func (adder *Adder) Finalize() (ipld.Node, error) { return nil, err } var root mfs.FSNode - root = mr.GetDirectory() + rootdir := mr.GetDirectory() + root = rootdir err = root.Flush() if err != nil { @@ -210,7 +211,7 @@ func (adder *Adder) Finalize() (ipld.Node, error) { var name string if !adder.Wrap { - children, err := root.(*mfs.Directory).ListNames(adder.ctx) + children, err := rootdir.ListNames(adder.ctx) if err != nil { return nil, err } @@ -219,16 +220,9 @@ func (adder *Adder) Finalize() (ipld.Node, error) { return nil, fmt.Errorf("expected at least one child dir, got none") } + // Replace root with the first child name = children[0] - - mr, err := adder.mfsRoot() - if err != nil { - return nil, err - } - - dir := mr.GetDirectory() - - root, err = dir.Child(name) + root, err = rootdir.Child(name) if err != nil { return nil, err }