Commit 31adaab5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make sure that tombstone markers are always readable.

Add test.
parent 8070e06a
......@@ -208,16 +208,26 @@ func (me *UnionFs) removeDeletion(name string) {
}
}
func (me *UnionFs) putDeletion(name string) fuse.Status {
func (me *UnionFs) putDeletion(name string) (code fuse.Status) {
marker := me.deletionPath(name)
me.deletionCache.AddEntry(path.Base(marker))
// Is there a WriteStringToFileOrDie ?
writable := me.fileSystems[0]
f, code := writable.Open(marker, uint32(os.O_TRUNC|os.O_WRONLY|os.O_CREATE))
fi, code := writable.GetAttr(marker)
if code.Ok() && fi.Size == int64(len(name)) {
return fuse.OK
}
var f fuse.File
if code == fuse.ENOENT {
f, code = writable.Create(marker, uint32(os.O_TRUNC|os.O_WRONLY), 0644)
} else {
writable.Chmod(marker, 0644)
f, code = writable.Open(marker, uint32(os.O_TRUNC|os.O_WRONLY))
}
if !code.Ok() {
log.Printf("could not create deletion file %v: %v",
marker, code)
log.Printf("could not create deletion file %v: %v", marker, code)
return fuse.EPERM
}
defer f.Release()
......
......@@ -178,6 +178,36 @@ func TestChmod(t *testing.T) {
}
}
func TestDelete(t *testing.T) {
wd, clean := setupUfs(t)
defer clean()
writeToFile(wd+"/ro/file", "a")
_, err := os.Lstat(wd + "/mount/file")
CheckSuccess(err)
err = os.Remove(wd + "/mount/file")
CheckSuccess(err)
_, err = os.Lstat(wd + "/mount/file")
if err == nil {
t.Fatal("should have disappeared.")
}
delPath := wd + "/rw/" + testOpts.DeletionDirName
names := dirNames(delPath)
if len(names) != 1 {
t.Fatal("Should have 1 deletion", names)
}
for k, _ := range names {
c, err := ioutil.ReadFile(delPath + "/" + k)
CheckSuccess(err)
if string(c) != "file" {
t.Fatal("content mismatch", string(c))
}
}
}
func TestBasic(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