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) {
fn := dir + "/file"
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755)
CheckSuccess(err)
defer f.Close()
fi, err := f.Stat()
CheckSuccess(err)
_, err = f.WriteString("hello")
CheckSuccess(err)
......@@ -178,5 +181,10 @@ func TestFSetAttr(t *testing.T) {
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.
}
......@@ -70,10 +70,13 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
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)
splitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
me.setOwner(&out.Attr)
out.Ino = nodeId
return out
}
func (me *fileSystemMount) getOpenedFile(h uint64) *openedFile {
......
......@@ -125,9 +125,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
if !code.Ok() {
return nil, code
}
out = &AttrOut{}
node.mount.fileInfoToAttr(fi, out)
out.Attr.Ino = header.NodeId
out = node.mount.fileInfoToAttr(fi, header.NodeId)
return out, OK
}
......@@ -211,9 +209,7 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
// the changes we effect here.
fi, code := node.fsInode.GetAttr(f, &header.Context)
if code.Ok() {
out = &AttrOut{}
out.Attr.Ino = header.NodeId
node.mount.fileInfoToAttr(fi, out)
out = node.mount.fileInfoToAttr(fi, header.NodeId)
}
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