Commit 1f07b43d authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use promoteDirsTo() for Rename and Mkdir too.

parent 03c3c9b9
...@@ -310,7 +310,11 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) { ...@@ -310,7 +310,11 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) {
if r.code != fuse.ENOENT { if r.code != fuse.ENOENT {
return syscall.EEXIST return syscall.EEXIST
} }
code = me.promoteDirsTo(path)
if code == fuse.OK {
code = me.fileSystems[0].Mkdir(path, mode) code = me.fileSystems[0].Mkdir(path, mode)
}
if code == fuse.OK { if code == fuse.OK {
me.removeDeletion(path) me.removeDeletion(path)
attr := &fuse.Attr{ attr := &fuse.Attr{
...@@ -619,23 +623,23 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status ...@@ -619,23 +623,23 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status
return stream, fuse.OK return stream, fuse.OK
} }
func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) { func (me *UnionFs) Rename(src string, dst string) (code fuse.Status) {
srcResult := me.getBranch(src) srcResult := me.getBranch(src)
if srcResult.code != fuse.OK { code = srcResult.code
return srcResult.code if code == fuse.OK {
code = srcResult.code
} }
if code == fuse.OK && srcResult.branch > 0 {
if srcResult.branch > 0 { code = me.Promote(src, srcResult)
code := me.Promote(src, srcResult)
if code != fuse.OK {
return code
} }
if code == fuse.OK {
code = me.promoteDirsTo(dst)
} }
code := me.fileSystems[0].Rename(src, dst) if code == fuse.OK {
if code != fuse.OK { code = me.fileSystems[0].Rename(src, dst)
return code
} }
if code == fuse.OK {
me.removeDeletion(dst) me.removeDeletion(dst)
srcResult.branch = 0 srcResult.branch = 0
me.branchCache.Set(dst, srcResult) me.branchCache.Set(dst, srcResult)
...@@ -648,7 +652,7 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) { ...@@ -648,7 +652,7 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) {
} else { } else {
code = me.putDeletion(src) code = me.putDeletion(src)
} }
}
return code return code
} }
......
...@@ -266,6 +266,7 @@ func TestOpenUndeletes(t *testing.T) { ...@@ -266,6 +266,7 @@ func TestOpenUndeletes(t *testing.T) {
_, err = os.Lstat(wd + "/mount/file") _, err = os.Lstat(wd + "/mount/file")
CheckSuccess(err) CheckSuccess(err)
} }
func TestMkdir(t *testing.T) { func TestMkdir(t *testing.T) {
wd, state := setup(t) wd, state := setup(t)
defer state.Unmount() defer state.Unmount()
...@@ -278,6 +279,22 @@ func TestMkdir(t *testing.T) { ...@@ -278,6 +279,22 @@ func TestMkdir(t *testing.T) {
CheckSuccess(err) CheckSuccess(err)
} }
func TestMkdirPromote(t *testing.T) {
wd, state := setup(t)
defer state.Unmount()
dirname := wd + "/ro/subdir/subdir2"
err := os.MkdirAll(dirname, 0755)
CheckSuccess(err)
err = os.Mkdir(wd+"/mount/subdir/subdir2/dir3", 0755)
CheckSuccess(err)
fi, _ := os.Lstat(wd+"/rw/subdir/subdir2/dir3")
CheckSuccess(err)
if fi == nil || !fi.IsDirectory() {
t.Error("is not a directory: ", fi)
}
}
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