Commit dfd98f27 authored by Stephen Whitmore's avatar Stephen Whitmore

mfs.Mkdir returns the final Directory it creates

License: MIT
Signed-off-by: default avatarStephen Whitmore <noffle@ipfs.io>
parent ca50f0d8
......@@ -650,7 +650,7 @@ Examples:
flush = true
}
err = mfs.Mkdir(n.FilesRoot, dirtomake, dashp, flush)
_, err = mfs.Mkdir(n.FilesRoot, dirtomake, dashp, flush)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......
......@@ -328,7 +328,7 @@ func (adder *Adder) addNode(node *dag.Node, path string) error {
dir := gopath.Dir(path)
if dir != "." {
if err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {
if _, err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {
return err
}
}
......@@ -399,7 +399,7 @@ func (adder *Adder) addFile(file files.File) error {
func (adder *Adder) addDir(dir files.File) error {
log.Infof("adding directory: %s", dir.FileName())
err := mfs.Mkdir(adder.mr, dir.FileName(), true, false)
_, err := mfs.Mkdir(adder.mr, dir.FileName(), true, false)
if err != nil {
return err
}
......
......@@ -100,9 +100,9 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
// Mkdir creates a directory at 'path' under the directory 'd', creating
// intermediary directories as needed if 'mkparents' is set to true
func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
func Mkdir(r *Root, pth string, mkparents bool, flush bool) (*Directory, error) {
if pth == "" {
return nil
return nil, nil
}
parts := path.SplitList(pth)
if parts[0] == "" {
......@@ -117,9 +117,9 @@ func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
if len(parts) == 0 {
// this will only happen on 'mkdir /'
if mkparents {
return nil
return nil, nil
}
return fmt.Errorf("cannot create directory '/': Already exists")
return nil, fmt.Errorf("cannot create directory '/': Already exists")
}
cur := r.GetValue().(*Directory)
......@@ -128,16 +128,16 @@ func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
if err == os.ErrNotExist && mkparents {
mkd, err := cur.Mkdir(d)
if err != nil {
return err
return nil, err
}
fsn = mkd
} else if err != nil {
return err
return nil, err
}
next, ok := fsn.(*Directory)
if !ok {
return fmt.Errorf("%s was not a directory", path.Join(parts[:i]))
return nil, fmt.Errorf("%s was not a directory", path.Join(parts[:i]))
}
cur = next
}
......@@ -145,18 +145,18 @@ func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
final, err := cur.Mkdir(parts[len(parts)-1])
if err != nil {
if !mkparents || err != os.ErrExist || final == nil {
return err
return nil, err
}
}
if flush {
err := final.Flush()
if err != nil {
return err
return nil, err
}
}
return nil
return final, nil
}
func Lookup(r *Root, path string) (FSNode, error) {
......
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