ioctx: use bytes for ListXattrs

Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@gmail.com>
This commit is contained in:
Abhishek Lekshmanan 2015-04-07 14:29:00 +05:30
parent ee55aa1810
commit 6324a7917d
2 changed files with 6 additions and 8 deletions

View File

@ -238,7 +238,7 @@ func (ioctx *IOContext) SetXattr(object string, name string, data []byte) error
// function that lists all the xattrs for an object, since xattrs are
// a k-v pair, this function returns a map of k-v pairs on
// success, error code on failure
func (ioctx *IOContext) ListXattrs(oid string) (map[string]string, error) {
func (ioctx *IOContext) ListXattrs(oid string) (map[string][]byte, error) {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
@ -249,7 +249,7 @@ func (ioctx *IOContext) ListXattrs(oid string) (map[string]string, error) {
return nil, RadosError(ret)
}
defer func() { C.rados_getxattrs_end(it) }()
m := make(map[string]string)
m := make(map[string][]byte)
for {
var c_name, c_val *C.char
var c_len C.size_t
@ -265,8 +265,6 @@ func (ioctx *IOContext) ListXattrs(oid string) (map[string]string, error) {
if c_name == nil {
return m, nil // stop iteration
}
m[C.GoString(c_name)] = C.GoStringN(c_val, (C.int)(c_len))
m[C.GoString(c_name)] = C.GoBytes(unsafe.Pointer(c_val), (C.int)(c_len))
}
panic("Invalid State")
}

View File

@ -489,16 +489,16 @@ func TestListXattrs(t *testing.T) {
err = pool.Write("obj", bytes_in, 0)
assert.NoError(t, err)
input_xattrs := make(map[string]string)
input_xattrs := make(map[string][]byte)
for i := 0; i < 200; i++ {
name := fmt.Sprintf("key_%d", i)
data := []byte(GetUUID())
err = pool.SetXattr("obj", name, data)
assert.NoError(t, err)
input_xattrs[name] = string(data)
input_xattrs[name] = data
}
output_xattrs := make(map[string]string)
output_xattrs := make(map[string][]byte)
output_xattrs, err = pool.ListXattrs("obj")
assert.NoError(t, err)
assert.Equal(t, len(input_xattrs), len(output_xattrs))