Exemple #1
0
// 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][]byte, error) {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	var it C.rados_xattrs_iter_t

	ret := C.rados_getxattrs(ioctx.ioctx, c_oid, &it)
	if ret < 0 {
		return nil, GetRadosError(ret)
	}
	defer func() { C.rados_getxattrs_end(it) }()
	m := make(map[string][]byte)
	for {
		var c_name, c_val *C.char
		var c_len C.size_t
		defer C.free(unsafe.Pointer(c_name))
		defer C.free(unsafe.Pointer(c_val))

		ret := C.rados_getxattrs_next(it, &c_name, &c_val, &c_len)
		if ret < 0 {
			return nil, GetRadosError(ret)
		}
		// rados api returns a null name,val & 0-length upon
		// end of iteration
		if c_name == nil {
			return m, nil // stop iteration
		}
		m[C.GoString(c_name)] = C.GoBytes(unsafe.Pointer(c_val), (C.int)(c_len))
	}
}
Exemple #2
0
// OpenAttributeList returns an iterator of the object's attributes.
func (o *Object) OpenAttributeList() (*AttributeList, error) {
	oid := C.CString(o.name)
	defer freeString(oid)
	var iterator C.rados_xattrs_iter_t
	ret := C.rados_getxattrs(o.ioContext, oid, &iterator)
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to retrieve attributes of object %s", o.name)
		return nil, err
	}
	al := &AttributeList{
		iterator: iterator,
	}
	return al, nil
}