Commit ec5217de authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add Rmdir and Mkdir to UnionFs.

parent 8b62c828
...@@ -257,11 +257,51 @@ func (me *UnionFs) Promote(name string, src *fuse.LoopbackFileSystem) fuse.Statu ...@@ -257,11 +257,51 @@ func (me *UnionFs) Promote(name string, src *fuse.LoopbackFileSystem) fuse.Statu
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Below: implement interface for a FileSystem. // Below: implement interface for a FileSystem.
func (me *UnionFs) Rmdir(path string) (code fuse.Status) {
r := me.branchCache.Get(path).(getBranchResult)
if r.code != fuse.OK {
return r.code
}
if r.attr.Mode & fuse.S_IFDIR == 0 {
return syscall.ENOTDIR
}
if r.branch > 0 {
stream, code := me.fileSystems[r.branch].OpenDir(path)
if code == fuse.OK {
_, ok := <-stream
if ok {
// TODO - should consume stream.
return syscall.ENOTEMPTY
}
}
me.putDeletion(path)
return fuse.OK
}
code = me.fileSystems[0].Rmdir(path)
if code != fuse.OK {
return code
}
r = me.branchCache.getDataNoCache(path).(getBranchResult)
if r.branch > 0 {
code = me.putDeletion(path)
}
return code
}
func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) { func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) {
r := me.branchCache.Get(path).(getBranchResult)
if r.code != fuse.ENOENT {
return syscall.EEXIST
}
code = me.fileSystems[0].Mkdir(path, mode) code = me.fileSystems[0].Mkdir(path, mode)
if code == fuse.OK { if code == fuse.OK {
go me.removeDeletion(path) me.removeDeletion(path)
me.branchCache.Set(path, getBranchResult{nil, fuse.OK, 0}) attr := &fuse.Attr{
Mode: fuse.S_IFDIR | mode,
}
me.branchCache.Set(path, getBranchResult{attr, fuse.OK, 0})
} }
return code return code
} }
...@@ -269,7 +309,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) { ...@@ -269,7 +309,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) {
func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status) { func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status) {
code = me.fileSystems[0].Symlink(pointedTo, linkName) code = me.fileSystems[0].Symlink(pointedTo, linkName)
if code == fuse.OK { if code == fuse.OK {
go me.removeDeletion(linkName) me.removeDeletion(linkName)
me.branchCache.Set(linkName, getBranchResult{nil, fuse.OK, 0}) me.branchCache.Set(linkName, getBranchResult{nil, fuse.OK, 0})
} }
return code return code
......
...@@ -43,7 +43,7 @@ func setup(t *testing.T) (workdir string, state *fuse.MountState) { ...@@ -43,7 +43,7 @@ func setup(t *testing.T) (workdir string, state *fuse.MountState) {
connector := fuse.NewFileSystemConnector(ufs, nil) connector := fuse.NewFileSystemConnector(ufs, nil)
state = fuse.NewMountState(connector) state = fuse.NewMountState(connector)
state.Mount(wd + "/mount") state.Mount(wd + "/mount")
// state.Debug = true state.Debug = true
go state.Loop(false) go state.Loop(false)
return wd, state return wd, state
...@@ -237,6 +237,18 @@ func TestPromote(t *testing.T) { ...@@ -237,6 +237,18 @@ func TestPromote(t *testing.T) {
writeToFile(wd + "/mount/subdir/file", "other-content", false) writeToFile(wd + "/mount/subdir/file", "other-content", false)
} }
func TestMkdir(t *testing.T) {
wd, state := setup(t)
defer state.Unmount()
dirname := wd + "/mount/subdir"
err := os.Mkdir(dirname, 0755)
CheckSuccess(err)
err = os.Remove(dirname)
CheckSuccess(err)
}
func TestRename(t *testing.T) { func TestRename(t *testing.T) {
type Config struct { type Config struct {
f1_ro bool f1_ro bool
......
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