Commit 6584ea29 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

UnionFs: Implement Truncate

parent d4933eb8
...@@ -321,6 +321,18 @@ func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status) ...@@ -321,6 +321,18 @@ func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status)
return code return code
} }
func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) {
branch := me.getBranch(path)
if branch > 0 {
code := me.Promote(path, me.branches[branch])
if code != fuse.OK {
return code
}
}
return me.fileSystems[0].Truncate(path, offset)
}
func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) { func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) {
r := me.branchCache.Get(name).(getBranchResult) r := me.branchCache.Get(name).(getBranchResult)
if r.attr == nil || r.code != fuse.OK { if r.attr == nil || r.code != fuse.OK {
......
...@@ -333,3 +333,20 @@ func TestWritableDir(t *testing.T) { ...@@ -333,3 +333,20 @@ func TestWritableDir(t *testing.T) {
t.Errorf("unexpected permission %o", fi.Permission()) t.Errorf("unexpected permission %o", fi.Permission())
} }
} }
func TestTruncate(t *testing.T) {
t.Log("TestTruncate")
wd, state := setup(t)
defer state.Unmount()
writeToFile(wd+"/ro/file", "hello")
os.Truncate(wd+"/mount/file", 2)
content := readFromFile(wd+"/mount/file")
if content != "he" {
t.Errorf("unexpected content %v", content)
}
content2 := readFromFile(wd+"/rw/file")
if content2 != content {
t.Errorf("unexpected rw content %v", content2)
}
}
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