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 a9f0c12
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ func (adder *Adder) addNode(node *dag.Node, path string) error {
path = key.Pretty()
}

dir := gopath.Dir(path)
if dir != "." {
if err := mfs.Mkdir(adder.mr, dir, true); err != nil {
return err
}
}

if err := mfs.PutNode(adder.mr, path, node); err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion mfs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ func (d *Directory) Mkdir(name string) (*Directory, error) {
return nil, err
}

return d.childDir(name)
dirobj := NewDirectory(d.ctx, name, ndir, d, d.dserv)
d.childDirs[name] = dirobj
return dirobj, nil
}

func (d *Directory) Unlink(name string) error {
Expand Down
5 changes: 4 additions & 1 deletion mfs/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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 a9f0c12

Please sign in to comment.