Commit 5ec71529 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Change fileInfoToAttr() so it takes a Inode argument.

This prevents forgetting or overwriting the Ino field.  Add a test.
parent 9b080253
...@@ -150,9 +150,12 @@ func TestFSetAttr(t *testing.T) { ...@@ -150,9 +150,12 @@ func TestFSetAttr(t *testing.T) {
fn := dir + "/file" fn := dir + "/file"
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755) f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755)
CheckSuccess(err) CheckSuccess(err)
defer f.Close() defer f.Close()
fi, err := f.Stat()
CheckSuccess(err)
_, err = f.WriteString("hello") _, err = f.WriteString("hello")
CheckSuccess(err) CheckSuccess(err)
...@@ -178,5 +181,10 @@ func TestFSetAttr(t *testing.T) { ...@@ -178,5 +181,10 @@ func TestFSetAttr(t *testing.T) {
fs.file.FileInfo.Atime_ns, fs.file.FileInfo.Mtime_ns) fs.file.FileInfo.Atime_ns, fs.file.FileInfo.Mtime_ns)
} }
newFi, err := f.Stat()
CheckSuccess(err)
if fi.Ino != newFi.Ino {
t.Errorf("f.Lstat().Ino = %d. Returned %d before.", newFi.Ino, fi.Ino)
}
// TODO - test chown if run as root. // TODO - test chown if run as root.
} }
...@@ -70,10 +70,13 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) { ...@@ -70,10 +70,13 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
return out return out
} }
func (me *fileSystemMount) fileInfoToAttr(fi *os.FileInfo, out *AttrOut) { func (me *fileSystemMount) fileInfoToAttr(fi *os.FileInfo, nodeId uint64) (out *AttrOut) {
out = &AttrOut{}
CopyFileInfo(fi, &out.Attr) CopyFileInfo(fi, &out.Attr)
splitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) splitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
me.setOwner(&out.Attr) me.setOwner(&out.Attr)
out.Ino = nodeId
return out
} }
func (me *fileSystemMount) getOpenedFile(h uint64) *openedFile { func (me *fileSystemMount) getOpenedFile(h uint64) *openedFile {
......
...@@ -125,9 +125,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out ...@@ -125,9 +125,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
if !code.Ok() { if !code.Ok() {
return nil, code return nil, code
} }
out = &AttrOut{} out = node.mount.fileInfoToAttr(fi, header.NodeId)
node.mount.fileInfoToAttr(fi, out)
out.Attr.Ino = header.NodeId
return out, OK return out, OK
} }
...@@ -211,9 +209,7 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out ...@@ -211,9 +209,7 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
// the changes we effect here. // the changes we effect here.
fi, code := node.fsInode.GetAttr(f, &header.Context) fi, code := node.fsInode.GetAttr(f, &header.Context)
if code.Ok() { if code.Ok() {
out = &AttrOut{} out = node.mount.fileInfoToAttr(fi, header.NodeId)
out.Attr.Ino = header.NodeId
node.mount.fileInfoToAttr(fi, out)
} }
return out, code return out, code
} }
......
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