Commit 50967bcd authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fix SetAttr for timestamps and uid/gid.

parent f6be67e0
......@@ -122,6 +122,18 @@ func (me *testCase) testOpenUnreadable() {
}
}
func (me *testCase) testTouch() {
log.Println("testTouch")
me.writeOrigFile()
err := os.Chtimes(me.mountFile, 42e9, 43e9)
CheckSuccess(err)
fi, err := os.Lstat(me.mountFile)
CheckSuccess(err)
if fi.Atime_ns != 42e9 || fi.Mtime_ns != 43e9 {
me.tester.Errorf("Got wrong timestamps %v", fi)
}
}
func (me *testCase) testReadThrough() {
me.writeOrigFile()
......@@ -558,7 +570,6 @@ func TestMount(t *testing.T) {
ts := new(testCase)
ts.Setup(t)
defer ts.Cleanup()
ts.testOverwriteRename()
ts.testDelRename()
ts.testOpenUnreadable()
......@@ -573,6 +584,7 @@ func TestMount(t *testing.T) {
ts.testFSync()
ts.testLargeRead()
ts.testLargeDirRead()
ts.testTouch()
}
func TestReadOnly(t *testing.T) {
......
......@@ -6,6 +6,7 @@ import (
"log"
"bytes"
"path/filepath"
"time"
)
......@@ -257,21 +258,22 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
if input.Valid&FATTR_MODE != 0 {
err = mount.fs.Chmod(fullPath, input.Mode)
}
if err != OK && (input.Valid&FATTR_UID != 0 || input.Valid&FATTR_GID != 0) {
if err == OK && (input.Valid&FATTR_UID != 0 || input.Valid&FATTR_GID != 0) {
// TODO - can we get just FATTR_GID but not FATTR_UID ?
err = mount.fs.Chown(fullPath, uint32(input.Uid), uint32(input.Gid))
}
if input.Valid&FATTR_SIZE != 0 {
mount.fs.Truncate(fullPath, input.Size)
}
if err != OK && (input.Valid&FATTR_ATIME != 0 || input.Valid&FATTR_MTIME != 0) {
if err == OK && (input.Valid&FATTR_ATIME != 0 || input.Valid&FATTR_MTIME != 0) {
err = mount.fs.Utimens(fullPath,
uint64(input.Atime*1e9)+uint64(input.Atimensec),
uint64(input.Mtime*1e9)+uint64(input.Mtimensec))
}
if err != OK && (input.Valid&FATTR_ATIME_NOW != 0 || input.Valid&FATTR_MTIME_NOW != 0) {
// TODO - should set time to now. Maybe just reuse
// Utimens() ? Go has no UTIME_NOW unfortunately.
if err == OK && (input.Valid&FATTR_ATIME_NOW != 0 || input.Valid&FATTR_MTIME_NOW != 0) {
ns := time.Nanoseconds()
err = mount.fs.Utimens(fullPath, uint64(ns), uint64(ns))
}
if err != OK {
return nil, err
......
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