// Set an xattr for an object identified by its key. func (c *Context) SetXattr(key, name string, value []byte) error { ckey := C.CString(key) defer C.free(unsafe.Pointer(ckey)) cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) cdata, cdatalen := byteSliceToBuffer(value) if cerr := C.rados_setxattr(c.ctx, ckey, cname, cdata, cdatalen); cerr < 0 { return radosReturnCodeError(cerr) } return nil }
// Sets an xattr for an object with key `name` with value as `data` func (ioctx *IOContext) SetXattr(object string, name string, data []byte) error { c_object := C.CString(object) c_name := C.CString(name) defer C.free(unsafe.Pointer(c_object)) defer C.free(unsafe.Pointer(c_name)) ret := C.rados_setxattr( ioctx.ioctx, c_object, c_name, (*C.char)(unsafe.Pointer(&data[0])), (C.size_t)(len(data))) return GetRadosError(ret) }
// SetAttribute sets an extended attribute of the object. func (o *Object) SetAttribute(attributeName string, attributeValue io.Reader) error { object := C.CString(o.name) attribute := C.CString(attributeName) defer freeString(object) defer freeString(attribute) bufAddr, bufLen := readerToBuf(attributeValue) ret := C.rados_setxattr(o.ioContext, object, attribute, bufAddr, bufLen) if err := toRadosError(ret); err != nil { err.Message = fmt.Sprintf("Unable to set attribute %s of object %s.", attributeName, o.name) return err } return nil }
func (r *RadosIoCtx) SetXattr(oid, name, value string) error { cname := C.CString(name) coid := C.CString(oid) cvalue := C.CString(value) defer func() { C.free(unsafe.Pointer(cname)) C.free(unsafe.Pointer(coid)) C.free(unsafe.Pointer(cvalue)) }() cerr := C.rados_setxattr(*r.ctx, coid, cname, cvalue, C.size_t(len(value))) if cerr < 0 { return errors.New("set xattr failed") } return nil }