]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: rework full_object_name() and friends
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 6 Jan 2016 00:03:49 +0000 (19:03 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:23 +0000 (12:07 -0500)
Flex RGWFileHandle::full_object_name() to build either a search
prefix (omits leading "/" and bucket name) or else the full path
to the root (e.g., for pretty-printing), depending on the value
of a boolean omit_bucket argument.

New convenience methods search_prefix() and relative_object_name()
select these, respectively.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index 8fcefd0074141211fbb4e5c2d7dc64a5dbe55399..9a29675dddfe5950bfd5aa017a60b095e056ec52 100644 (file)
@@ -264,7 +264,7 @@ namespace rgw {
 
     if (! f->write_req) {
       /* start */
-      std::string object_name = full_object_name();
+      std::string object_name = relative_object_name();
       f->write_req =
        new RGWWriteRequest(fs->get_context(), fs->get_user(), this,
                            bucket_name(), object_name);
@@ -662,7 +662,7 @@ int rgw_mkdir(struct rgw_fs *rgw_fs,
     buffer::list bl;
     fhr = fs->lookup_fh(parent, name, RGWFileHandle::FLAG_PSEUDO);
     rgw_fh = get<0>(fhr);
-    string dir_name = rgw_fh->full_object_name() + "/";
+    string dir_name = rgw_fh->relative_object_name() + "/";
     RGWPutObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
                         dir_name, bl);
     rc = librgw.get_fe()->execute_req(&req);
@@ -725,7 +725,7 @@ int rgw_unlink(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh,
     if (! rc)  {
       /* rgw_fh ref+ */
       RGWFileHandle* rgw_fh = get_rgwfh(fh);
-      std::string oname = rgw_fh->full_object_name();
+      std::string oname = rgw_fh->relative_object_name();
       RGWDeleteObjRequest req(cct, fs->get_user(), parent->bucket_name(),
                              oname);
       rc = librgw.get_fe()->execute_req(&req);
@@ -1115,7 +1115,7 @@ int rgw_readv(struct rgw_fs *rgw_fs,
                            static_cast<char*>(vio->vio_base)));
   }
 
-  std::string oname = rgw_fh->full_object_name();
+  std::string oname = rgw_fh->relative_object_name();
   RGWPutObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
                       oname, bl);
 
index 85f548560d3eb918bd4bbcd9bf5496a339091f40..1d3eb6106459c2374a4f6b6bd41d0edd1107273a 100644 (file)
@@ -320,15 +320,15 @@ namespace rgw {
 
     const std::string& object_name() const { return name; }
 
-    std::string full_object_name(uint8_t min_depth = 1) {
-      if (depth <= min_depth) {
+    std::string full_object_name(bool omit_bucket = false) {
+      if (depth <= 1) {
        return "";
       }
       std::string path;
       std::vector<const std::string*> segments;
       int reserve = 0;
       RGWFileHandle* tfh = this;
-      while (tfh && !tfh->is_bucket()) {
+      while (tfh && !tfh->is_root() && !(tfh->is_bucket() && omit_bucket)) {
        segments.push_back(&tfh->object_name());
        reserve += (1 + tfh->object_name().length());
        tfh = tfh->parent;
@@ -338,13 +338,25 @@ namespace rgw {
       for (auto& s : boost::adaptors::reverse(segments)) {
        if (! first)
          path += "/";
-       else
+       else {
+         if (!omit_bucket && (path.front() != '/')) // pretty-print
+           path += "/";
          first = false;
+       }
        path += *s;
       }
       return path;
     }
 
+    inline std::string relative_object_name() {
+      return full_object_name(false /* omit_bucket */);
+    }
+
+
+    inline std::string search_prefix() {
+      return full_object_name(true /* omit_bucket */);
+    }
+    
     inline std::string make_key_name(const char *name) {
       std::string key_name{full_object_name()};
       if (key_name.length() > 0)
@@ -922,7 +934,7 @@ public:
     // woo
     s->user = user;
 
-    prefix = rgw_fh->full_object_name();
+    prefix = rgw_fh->search_prefix();
     if (prefix.length() > 0)
       prefix += "/";
     delimiter = '/';
@@ -1574,7 +1586,7 @@ public:
     // woo
     s->user = user;
 
-    prefix = rgw_fh->full_object_name();
+    prefix = rgw_fh->search_prefix();
     if (prefix.length() > 0)
       prefix += "/";
     prefix += path;