Skip to content

Commit

Permalink
PutNode creates intermediary nodes
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Dec 28, 2015
1 parent 38f86f0 commit 63dcd20
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mfs/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func lookupDir(r *Root, path string) (*Directory, error) {
// PutNode inserts 'nd' at 'path' in the given mfs
func PutNode(r *Root, path string, nd *dag.Node) error {
dirp, filename := gopath.Split(path)
err := Mkdir(r, dirp, true)
if err != nil {
return err
}

pdir, err := lookupDir(r, dirp)
if err != nil {
Expand Down Expand Up @@ -116,7 +120,10 @@ func Mkdir(r *Root, pth string, parents bool) error {

if len(parts) == 0 {
// this will only happen on 'mkdir /'
return fmt.Errorf("cannot mkdir '%s'", pth)
if parents {
return nil
}
return fmt.Errorf("cannot create directory '/': Already exists")
}

cur := r.GetValue().(*Directory)
Expand Down

0 comments on commit 63dcd20

Please sign in to comment.