Commit f548a404 authored by Jeromy's avatar Jeromy

just flush dir in mkdir flush, not whole tree

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent e3769dfb
......@@ -586,24 +586,17 @@ Examples:
return
}
err = mfs.Mkdir(n.FilesRoot, dirtomake, dashp)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
flush, found, _ := req.Option("flush").Bool()
if !found {
flush = true
}
if flush {
err := n.FilesRoot.Flush()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = mfs.Mkdir(n.FilesRoot, dirtomake, dashp, flush)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
},
}
......
......@@ -330,7 +330,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); err != nil {
if err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {
return err
}
}
......@@ -403,7 +403,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)
err := mfs.Mkdir(adder.mr, dir.FileName(), true, false)
if err != nil {
return err
}
......
......@@ -278,11 +278,6 @@ func (d *Directory) Mkdir(name string) (*Directory, error) {
return nil, err
}
err = d.flushUp()
if err != nil {
return nil, err
}
dirobj := NewDirectory(d.ctx, name, ndir, d, d.dserv)
d.childDirs[name] = dirobj
return dirobj, nil
......@@ -300,12 +295,21 @@ func (d *Directory) Unlink(name string) error {
return err
}
return d.flushUp()
_, err = d.dserv.Add(d.node)
if err != nil {
return err
}
return d.parent.closeChild(d.name, d.node)
}
func (d *Directory) flushUp() error {
func (d *Directory) Flush() error {
nd, err := d.flushCurrentNode()
if err != nil {
return err
}
return d.parent.closeChild(d.name, d.node)
return d.parent.closeChild(d.name, nd)
}
// AddChild adds the node 'nd' under this directory giving it the name 'name'
......
......@@ -100,7 +100,7 @@ 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 'parents' is set to true
func Mkdir(r *Root, pth string, parents bool) error {
func Mkdir(r *Root, pth string, parents bool, flush bool) error {
if pth == "" {
return nil
}
......@@ -142,13 +142,20 @@ func Mkdir(r *Root, pth string, parents bool) error {
cur = next
}
_, err := cur.Mkdir(parts[len(parts)-1])
final, err := cur.Mkdir(parts[len(parts)-1])
if err != nil {
if !parents || err != os.ErrExist {
return err
}
}
if flush {
err := final.Flush()
if err != nil {
return err
}
}
return nil
}
......
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