mirror of https://github.com/ceph/go-ceph
cephfs: add file method RemoveXattr implementing ceph_fremovexattr
Add RemoveXattr implementing ceph_fremovexattr as well as a test for it. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
04bf7a4d0e
commit
5f41e2d8d2
|
@ -138,3 +138,24 @@ func (f *File) ListXattr() ([]string, error) {
|
|||
}
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// RemoveXattr removes the named xattr from the open file.
|
||||
//
|
||||
// Implements:
|
||||
// int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name);
|
||||
func (f *File) RemoveXattr(name string) error {
|
||||
if err := f.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if name == "" {
|
||||
return errInvalid
|
||||
}
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
ret := C.ceph_fremovexattr(
|
||||
f.mount.mount,
|
||||
f.fd,
|
||||
cName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
|
|
@ -118,3 +118,40 @@ func TestListXattr(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemoveXattr(t *testing.T) {
|
||||
mount := fsConnect(t)
|
||||
defer fsDisconnect(t, mount)
|
||||
fname := "TestRemoveXattr.txt"
|
||||
|
||||
f, err := mount.Open(fname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
assert.NoError(t, f.Close())
|
||||
assert.NoError(t, mount.Unlink(fname))
|
||||
}()
|
||||
|
||||
t.Run("removeXattr", func(t *testing.T) {
|
||||
s := samples[0]
|
||||
err := f.SetXattr(s.name, s.value, XattrDefault)
|
||||
err = f.RemoveXattr(s.name)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("removeMissingXattr", func(t *testing.T) {
|
||||
s := samples[1]
|
||||
err := f.RemoveXattr(s.name)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("emptyName", func(t *testing.T) {
|
||||
err := f.RemoveXattr("")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("invalidFile", func(t *testing.T) {
|
||||
f1 := &File{}
|
||||
err := f1.RemoveXattr(samples[0].name)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue