From aee654916ba18c1ac3c41a641c3c05a3b0cec592 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sat, 30 Mar 2013 18:15:12 +0100 Subject: [PATCH] fix nspace assignment in LFNIndex::lfn_parse_object_name The unused ns variable is assigned to the nspace data member of the parsed hobject_t. It would be nicer to use a constructor accepting the namespace in argument. http://tracker.ceph.com/issues/4597 refs #4597 Signed-off-by: Loic Dachary --- src/os/LFNIndex.cc | 1 + src/test/os/TestLFNIndex.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/os/LFNIndex.cc b/src/os/LFNIndex.cc index 62b8f7085e16..12aabfd8fd1a 100644 --- a/src/os/LFNIndex.cc +++ b/src/os/LFNIndex.cc @@ -1073,6 +1073,7 @@ bool LFNIndex::lfn_parse_object_name(const string &long_name, hobject_t *out) { pool = strtoull(pstring.c_str(), NULL, 16); (*out) = hobject_t(name, key, snap, hash, (int64_t)pool); + out->nspace = ns; return true; } diff --git a/src/test/os/TestLFNIndex.cc b/src/test/os/TestLFNIndex.cc index 3666de0ede15..eeacf1ab8fb6 100644 --- a/src/test/os/TestLFNIndex.cc +++ b/src/test/os/TestLFNIndex.cc @@ -131,6 +131,35 @@ TEST_F(TestHASH_INDEX_TAG_2, generate_and_parse_name) { "\\dA_KEY_head_ABABABAB"); } +class TestHOBJECT_WITH_POOL : public TestWrapLFNIndex, public ::testing::Test { +public: + TestHOBJECT_WITH_POOL() : TestWrapLFNIndex(coll_t("ABC"), "PATH", CollectionIndex::HOBJECT_WITH_POOL) { + } +}; + +TEST_F(TestHOBJECT_WITH_POOL, generate_and_parse_name) { + const vector path; + std::string mangled_name; + const std::string key("KEY"); + uint64_t hash = 0xABABABAB; + uint64_t pool = 0xCDCDCDCD; + + { + std::string name(".XA/B_\\C.D"); + name[1] = '\0'; + hobject_t hoid(object_t(name), key, CEPH_NOSNAP, hash, pool); + hoid.nspace = "NSPACE"; + + test_generate_and_parse(hoid, "\\.\\nA\\sB\\u\\\\C.D_KEY_head_ABABABAB_NSPACE_cdcdcdcd"); + } + { + hobject_t hoid(object_t("DIR_A"), key, CEPH_NOSNAP, hash, pool); + hoid.nspace = "NSPACE"; + + test_generate_and_parse(hoid, "\\dA_KEY_head_ABABABAB_NSPACE_cdcdcdcd"); + } +} + class TestLFNIndex : public TestWrapLFNIndex, public ::testing::Test { public: TestLFNIndex() : TestWrapLFNIndex(coll_t("ABC"), "PATH", CollectionIndex::HASH_INDEX_TAG) { -- 2.47.3