Commit 22dcd8c5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

On rename of a directory with contents, generate deletion entries for

all files.

This makes serializing file changes easier, as all removed files will
have explicit deletion entries.
parent 6ad9f444
......@@ -401,6 +401,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32, context *fuse.Context) (code
var stream chan fuse.DirEntry
stream, code = me.OpenDir(path, context)
if code.Ok() {
// This shouldn't happen, but let's be safe.
for entry := range stream {
me.putDeletion(filepath.Join(path, entry.Name))
}
......@@ -765,7 +766,8 @@ func (me *UnionFs) OpenDir(directory string, context *fuse.Context) (stream chan
}
// recursivePromote promotes path, and if a directory, everything
// below that directory. It returns a list of all promoted paths.
// below that directory. It returns a list of all promoted paths, in
// full, including the path itself.
func (me *UnionFs) recursivePromote(path string, pathResult branchResult, context *fuse.Context) (names []string, code fuse.Status) {
names = []string{}
if pathResult.branch > 0 {
......@@ -816,18 +818,16 @@ func (me *UnionFs) renameDirectory(srcResult branchResult, srcDir string, dstDir
relative := strings.TrimLeft(srcName[len(srcDir):], string(filepath.Separator))
dst := filepath.Join(dstDir, relative)
me.removeDeletion(dst)
}
srcResult := me.getBranch(srcDir)
srcResult.branch = 0
me.branchCache.Set(dstDir, srcResult)
srcResult := me.getBranch(srcName)
srcResult.branch = 0
me.branchCache.Set(dst, srcResult)
srcResult = me.branchCache.GetFresh(srcDir).(branchResult)
if srcResult.branch > 0 {
code = me.putDeletion(srcDir)
srcResult = me.branchCache.GetFresh(srcName).(branchResult)
if srcResult.branch > 0 {
code = me.putDeletion(srcName)
}
}
// TODO - should issue invalidations against promoted files?
}
return code
}
......
......@@ -475,6 +475,25 @@ func TestRenameDirBasic(t *testing.T) {
}
}
func TestRenameDirAllSourcesGone(t *testing.T) {
wd, clean := setupUfs(t)
defer clean()
err := os.MkdirAll(wd+"/ro/dir", 0755)
CheckSuccess(err)
err = ioutil.WriteFile(wd+"/ro/dir/file.txt", []byte{42}, 0644)
CheckSuccess(err)
err = os.Rename(wd+"/mount/dir", wd+"/mount/renamed")
CheckSuccess(err)
names := dirNames(wd + "/rw/" + testOpts.DeletionDirName)
if len(names) != 2 {
t.Errorf("Expected 2 entries in %v", names)
}
}
func TestRenameDirWithDeletions(t *testing.T) {
wd, clean := setupUfs(t)
defer clean()
......
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