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

Test and fix truncate on open file.

parent b189413a
......@@ -178,13 +178,17 @@ func (me *memNode) GetAttr(file File, context *Context) (fi *os.FileInfo, code S
func (me *memNode) Truncate(file File, size uint64, context *Context) (code Status) {
if file != nil {
return file.Truncate(size)
}
me.info.Size = int64(size)
code = file.Truncate(size)
} else {
err := os.Truncate(me.filename(), int64(size))
code = ToStatus(err)
}
if code.Ok() {
me.info.Ctime_ns = time.Nanoseconds()
return ToStatus(err)
// TODO - should update mtime too?
me.info.Size = int64(size)
}
return code
}
func (me *memNode) Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status) {
......
......@@ -58,3 +58,21 @@ func TestMemNodeFs(t *testing.T) {
t.Fatalf("Readdir got %v, expected 1 file named 'test'", entries)
}
}
func TestMemNodeSetattr(t *testing.T) {
wd, _, clean := setupMemNodeTest(t)
defer clean()
f, err := os.OpenFile(wd+"/test", os.O_CREATE|os.O_WRONLY, 0644)
CheckSuccess(err)
defer f.Close()
err = f.Truncate(4096)
CheckSuccess(err)
fi, err := f.Stat()
CheckSuccess(err)
if fi.Size != 4096 {
t.Errorf("Size should be 4096 after Truncate: %d", fi.Size)
}
}
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