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