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

Fix SetXAttr in xattr_test: must copy attribute value.

parent 800e5338
...@@ -39,10 +39,13 @@ func (me *XAttrTestFs) GetAttr(name string) (*Attr, Status) { ...@@ -39,10 +39,13 @@ func (me *XAttrTestFs) GetAttr(name string) (*Attr, Status) {
} }
func (me *XAttrTestFs) SetXAttr(name string, attr string, data []byte, flags int) Status { func (me *XAttrTestFs) SetXAttr(name string, attr string, data []byte, flags int) Status {
log.Println("SetXAttr", name, attr, string(data), flags)
if name != me.filename { if name != me.filename {
return ENOENT return ENOENT
} }
me.attrs[attr] = data dest := make([]byte, len(data))
copy(dest, data)
me.attrs[attr] = dest
return OK return OK
} }
...@@ -54,7 +57,7 @@ func (me *XAttrTestFs) GetXAttr(name string, attr string) ([]byte, Status) { ...@@ -54,7 +57,7 @@ func (me *XAttrTestFs) GetXAttr(name string, attr string) ([]byte, Status) {
if !ok { if !ok {
return nil, syscall.ENODATA return nil, syscall.ENODATA
} }
log.Println("GetXAttr", string(v))
return v, OK return v, OK
} }
...@@ -74,7 +77,7 @@ func (me *XAttrTestFs) RemoveXAttr(name string, attr string) Status { ...@@ -74,7 +77,7 @@ func (me *XAttrTestFs) RemoveXAttr(name string, attr string) Status {
return ENOENT return ENOENT
} }
_, ok := me.attrs[attr] _, ok := me.attrs[attr]
log.Println(name, attr, ok) log.Println("RemoveXAttr", name, attr, ok)
if !ok { if !ok {
return syscall.ENODATA return syscall.ENODATA
} }
...@@ -90,7 +93,7 @@ func TestXAttrRead(t *testing.T) { ...@@ -90,7 +93,7 @@ func TestXAttrRead(t *testing.T) {
"user.attr2": []byte("val2")} "user.attr2": []byte("val2")}
xfs := NewXAttrFs(nm, golden) xfs := NewXAttrFs(nm, golden)
connector := NewPathFileSystemConnector(xfs) connector := NewPathFileSystemConnector(NewLockingPathFilesystem(xfs))
mountPoint := MakeTempDir() mountPoint := MakeTempDir()
state := NewMountState(connector) state := NewMountState(connector)
...@@ -136,10 +139,13 @@ func TestXAttrRead(t *testing.T) { ...@@ -136,10 +139,13 @@ func TestXAttrRead(t *testing.T) {
} }
} }
Setxattr(mounted, "third", []byte("value"), 0) errno = Setxattr(mounted, "third", []byte("value"), 0)
if errno != 0 {
t.Error("Setxattr error", errno)
}
val, errno = GetXAttr(mounted, "third") val, errno = GetXAttr(mounted, "third")
if errno != 0 || string(val) != "value" { if errno != 0 || string(val) != "value" {
t.Error("Read back set xattr:", errno, val) t.Error("Read back set xattr:", errno, string(val))
} }
Removexattr(mounted, "third") Removexattr(mounted, "third")
......
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