From: Matt Benjamin Date: Tue, 12 Jan 2016 23:21:56 +0000 (-0500) Subject: librgw: fix leading-slash special case, again X-Git-Tag: v10.1.0~382^2~35 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35445cf7df8d0852b06954dd4e8d8ddde926f334;p=ceph.git librgw: fix leading-slash special case, again Fix boilerplate to sanitize relative_object_name() in rgw_create as well as the RGWStatObjRequest case of RGWLibFS::stat_leaf. Signed-off-by: Matt Benjamin Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 86c57f418a83..07962edafe4e 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -91,7 +91,8 @@ namespace rgw { case 0: { std::string obj_name{parent->relative_object_name()}; - if (obj_name.back() != '/') + if ((obj_name.length() > 0) && + (obj_name.back() != '/')) obj_name += "/"; obj_name += path; RGWStatObjRequest req(cct, get_user(), @@ -692,7 +693,11 @@ int rgw_create(struct rgw_fs *rgw_fs, return -EEXIST; } else { /* expand and check name */ - std::string obj_name{parent->relative_object_name() + "/" + name}; + std::string obj_name{parent->relative_object_name()}; + if ((obj_name.size() > 0) && + (obj_name.back() != '/')) + obj_name += "/"; + obj_name += name; if (! valid_s3_object_name(obj_name)) { return -EINVAL; } else { @@ -858,37 +863,6 @@ int rgw_unlink(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, return -rc; } -void dump_buckets(void) { - /* get the bucket list */ - string marker; // XXX need to match offset - string end_marker; - uint64_t bucket_count, bucket_objcount; - - RGWUserBuckets buckets; - uint64_t max_buckets = g_ceph_context->_conf->rgw_list_buckets_max_chunk; - bool is_truncated; - - RGWRados* store = rgwlib.get_store(); - - /* XXX check offsets */ - uint64_t ix = 3; - rgw_user uid("testuser"); - int rc = rgw_read_user_buckets(store, uid, buckets, marker, end_marker, - max_buckets, true, &is_truncated); - if (rc == 0) { - bucket_count = 0; - bucket_objcount = 0; - map& m = buckets.get_buckets(); - for (auto& ib : m) { - RGWBucketEnt& bent = ib.second; - bucket_objcount += bent.count; - marker = ib.first; - std::cout << bent.bucket.name.c_str() << " ix: " << ix++ << std::endl; - } - bucket_count += m.size(); - } -} /* dump_buckets */ - /* lookup object by name (POSIX style) */ diff --git a/src/test/librgw_file.cc b/src/test/librgw_file.cc index ed1360940725..5ed0cb4077f3 100644 --- a/src/test/librgw_file.cc +++ b/src/test/librgw_file.cc @@ -72,14 +72,6 @@ TEST(LibRGW, GETATTR_ROOT) { } } -extern "C" { -extern void dump_buckets(void); -} - -TEST(LibRGW, DUMP_BUCKETS) { - dump_buckets(); -} - extern "C" { static bool r1_cb(const char* name, void *arg, uint64_t offset) { // don't need arg--it would point to fids1