13
13
#define READ_CHUNK_LEN (16 * 1024)
15
int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size)
15
static map<string, string> ext_mime_map;
17
int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive, map<string, bufferlist> *pattrs)
17
map<string,bufferlist> attrs;
19
map<string,bufferlist> no_attrs;
19
23
rgw_obj obj(bucket, oid);
21
int ret = rgwstore->put_obj(NULL, obj, data, size, NULL, attrs);
25
int ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, *pattrs);
23
27
if (ret == -ENOENT) {
24
ret = rgwstore->create_bucket(uid, bucket, attrs, true); //all callers are using system buckets
28
ret = rgwstore->create_bucket(uid, bucket, no_attrs, true); //all callers are using system buckets
26
ret = rgwstore->put_obj(NULL, obj, data, size, NULL, attrs);
30
ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, *pattrs);
38
42
bufferlist::iterator iter;
39
43
int request_len = READ_CHUNK_LEN;
40
44
rgw_obj obj(bucket, key);
41
ret = rgwstore->prepare_get_obj(ctx, obj, 0, NULL, NULL, NULL,
45
ret = rgwstore->prepare_get_obj(ctx, obj, NULL, NULL, NULL, NULL,
42
46
NULL, NULL, NULL, NULL, NULL, NULL, &handle, &err);
69
void parse_mime_map_line(const char *start, const char *end)
71
char line[end - start + 1];
72
strncpy(line, start, end - start);
73
line[end - start] = '\0';
75
#define DELIMS " \t\n\r"
80
char *mime = strsep(&l, DELIMS);
86
ext = strsep(&l, DELIMS);
88
ext_mime_map[ext] = mime;
94
void parse_mime_map(const char *buf)
96
const char *start = buf, *end = buf;
98
while (*end && *end != '\n') {
101
parse_mime_map_line(start, end);
107
static int ext_mime_map_init(const char *ext_map)
109
int fd = open(ext_map, O_RDONLY);
114
dout(0) << "ext_mime_map_init(): failed to open file=" << ext_map << " ret=" << ret << dendl;
119
ret = fstat(fd, &st);
122
dout(0) << "ext_mime_map_init(): failed to stat file=" << ext_map << " ret=" << ret << dendl;
126
buf = (char *)malloc(st.st_size + 1);
129
dout(0) << "ext_mime_map_init(): failed to allocate buf" << dendl;
133
ret = read(fd, buf, st.st_size + 1);
134
if (ret != st.st_size) {
135
// huh? file size has changed, what are the odds?
136
dout(0) << "ext_mime_map_init(): raced! will retry.." << dendl;
138
return ext_mime_map_init(ext_map);
140
buf[st.st_size] = '\0';
150
const char *rgw_find_mime_by_ext(string& ext)
152
map<string, string>::iterator iter = ext_mime_map.find(ext);
153
if (iter == ext_mime_map.end())
156
return iter->second.c_str();
159
int rgw_tools_init(CephContext *cct)
161
int ret = ext_mime_map_init(cct->_conf->rgw_mime_types_file.c_str());