]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add content-type to index dirent
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 18 Oct 2011 20:28:30 +0000 (13:28 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 18 Oct 2011 20:28:30 +0000 (13:28 -0700)
src/rgw/rgw_cls_api.h
src/rgw/rgw_formats.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 7d729844bdfd3ffdfc8ed26b0e4fdaf17e197e8f..3f2d21d8f2f66f7b86f0eab1ecc20a33b0027bcc 100644 (file)
@@ -49,9 +49,10 @@ struct rgw_bucket_dir_entry_meta {
   string owner;
   string owner_display_name;
   string tag;
+  string content_type;
 
   void encode(bufferlist &bl) const {
-    __u8 struct_v = 1;
+    __u8 struct_v = 2;
     ::encode(struct_v, bl);
     ::encode(category, bl);
     ::encode(size, bl);
@@ -59,6 +60,7 @@ struct rgw_bucket_dir_entry_meta {
     ::encode(etag, bl);
     ::encode(owner, bl);
     ::encode(owner_display_name, bl);
+    ::encode(content_type, bl);
   }
   void decode(bufferlist::iterator &bl) {
     __u8 struct_v;
@@ -69,6 +71,8 @@ struct rgw_bucket_dir_entry_meta {
     ::decode(etag, bl);
     ::decode(owner, bl);
     ::decode(owner_display_name, bl);
+    if (struct_v >= 2)
+      ::decode(content_type, bl);
   }
 };
 WRITE_CLASS_ENCODER(rgw_bucket_dir_entry_meta)
index 092cc028df71d9b446ce281d24e179e90923a103..4265a8bc94886e4ca342d3491a30602432534609 100644 (file)
@@ -126,6 +126,7 @@ void RGWFormatter_Plain::dump_format(const char *name, const char *fmt, ...)
     min_stack_level = stack.size();
 
   bool should_print = (stack.size() == min_stack_level && !entry.size);
+
   entry.size++;
 
   if (!should_print)
@@ -223,6 +224,7 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
 
   struct plain_stack_entry& entry = stack.back();
   bool should_print = (stack.size() == min_stack_level && !entry.size);
+
   entry.size++;
 
   if (!should_print)
@@ -231,5 +233,12 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
   va_start(ap, fmt);
   vsnprintf(buf, LARGE_SIZE, fmt, ap);
   va_end(ap);
-  write_data("%s\n", buf);
+
+  const char *eol;
+  if (len)
+    eol = "\n";
+  else
+    eol = "";
+
+  write_data("%s%s", eol, buf);
 }
index ed1178573d147cbc2568b4689a29bf44982b5d30..73bfb75f8c7516cfaf094abaaae0a9414dc3cab9 100644 (file)
@@ -623,6 +623,7 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj,  uint64_t s
   op.create(exclusive);
 
   string etag;
+  string content_type;
   bufferlist acl_bl;
 
   map<string, bufferlist>::iterator iter;
@@ -637,6 +638,8 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj,  uint64_t s
 
     if (name.compare(RGW_ATTR_ETAG) == 0) {
       etag = bl.c_str();
+    } else if (name.compare(RGW_ATTR_CONTENT_TYPE) == 0) {
+      content_type = bl.c_str();
     } else if (name.compare(RGW_ATTR_ACL) == 0) {
       acl_bl = bl;
     }
@@ -658,7 +661,7 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj,  uint64_t s
 
   utime_t ut = ceph_clock_now(g_ceph_context);
   r = complete_update_index(bucket, obj.object, tag, epoch, size,
-                            ut, etag, &acl_bl, category);
+                            ut, etag, content_type, &acl_bl, category);
 
   if (mtime) {
     r = io_ctx.stat(oid, NULL, mtime);
@@ -1487,7 +1490,7 @@ int RGWRados::prepare_update_index(RGWObjState *state, rgw_bucket& bucket, strin
 }
 
 int RGWRados::complete_update_index(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch, uint64_t size,
-                                    utime_t& ut, string& etag, bufferlist *acl_bl, RGWObjCategory category)
+                                    utime_t& ut, string& etag, string& content_type, bufferlist *acl_bl, RGWObjCategory category)
 {
   if (bucket.marker.empty())
     return 0;
@@ -1506,6 +1509,7 @@ int RGWRados::complete_update_index(rgw_bucket& bucket, string& oid, string& tag
   }
   ent.owner = owner.get_id();
   ent.owner_display_name = owner.get_display_name();
+  ent.content_type = content_type;
 
   int ret = cls_obj_complete_add(bucket, tag, epoch, ent, category);
 
@@ -1529,6 +1533,7 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
   RGWRadosCtx *rctx = (RGWRadosCtx *)ctx;
   uint64_t size = 0;
   string etag;
+  string content_type;
   bufferlist acl_bl;
 
   int r = open_bucket_ctx(bucket, io_ctx);
@@ -1552,6 +1557,8 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
 
     if (name.compare(RGW_ATTR_ETAG) == 0) {
       etag = bl.c_str();
+    } else if (name.compare(RGW_ATTR_CONTENT_TYPE) == 0) {
+      content_type = bl.c_str();
     } else if (name.compare(RGW_ATTR_ACL) == 0) {
       acl_bl = bl;
     }
@@ -1616,7 +1623,7 @@ done:
 
   if (ret >= 0) {
     ret = complete_update_index(bucket, dst_obj.object, tag, epoch, size,
-                                ut, etag, &acl_bl, category);
+                                ut, etag, content_type, &acl_bl, category);
   }
 
   return ret;
@@ -2080,6 +2087,7 @@ int RGWRados::cls_obj_complete_op(rgw_bucket& bucket, uint8_t op, string& tag, u
   call.meta.etag = ent.etag;
   call.meta.owner = ent.owner;
   call.meta.owner_display_name = ent.owner_display_name;
+  call.meta.content_type = ent.content_type;
   call.meta.category = category;
   ::encode(call, in);
   AioCompletion *c = librados::Rados::aio_create_completion(NULL, NULL, NULL);
@@ -2153,6 +2161,7 @@ int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, ma
     e.etag = dirent.meta.etag;
     e.owner = dirent.meta.owner;
     e.owner_display_name = dirent.meta.owner_display_name;
+    e.content_type = dirent.meta.content_type;
     m[e.name] = e;
     dout(0) << " got " << e.name << dendl;
   }
index 405d3d513c04dff803e44aa1bf2b8ea586dd2ce4..a2413c8309e7edbecb746e506043cc442b195bc3 100644 (file)
@@ -309,7 +309,7 @@ public:
   int cls_bucket_head(rgw_bucket& bucket, struct rgw_bucket_dir_header& header);
   int prepare_update_index(RGWObjState *state, rgw_bucket& bucket, string& oid, string& tag);
   int complete_update_index(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch, uint64_t size,
-                            utime_t& ut, string& etag, bufferlist *acl_bl, RGWObjCategory category);
+                            utime_t& ut, string& etag, string& content_type, bufferlist *acl_bl, RGWObjCategory category);
   int complete_update_index_del(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch) {
     return cls_obj_complete_del(bucket, tag, epoch, oid);
   }