From c16f2603aa156eba3909e96213ea705c13160b06 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 2 Sep 2011 14:32:04 -0700 Subject: [PATCH] LFNIndex: include index_version in the lfn attribute name While updating, we use hard links to populate the new directory. We need to change the lfn attribute to allow unlinking from the old directory to continue to work. Signed-off-by: Samuel Just --- src/os/LFNIndex.cc | 6 +++--- src/os/LFNIndex.h | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/os/LFNIndex.cc b/src/os/LFNIndex.cc index 8674c6a17eca4..126a4b9edbdb4 100644 --- a/src/os/LFNIndex.cc +++ b/src/os/LFNIndex.cc @@ -555,7 +555,7 @@ int LFNIndex::lfn_get_name(const vector &path, for ( ; ; ++i) { candidate = lfn_get_short_name(hoid, i); candidate_path = get_full_path(path, candidate); - r = do_getxattr(candidate_path.c_str(), LFN_ATTR.c_str(), buf, sizeof(buf)); + r = do_getxattr(candidate_path.c_str(), get_lfn_attr().c_str(), buf, sizeof(buf)); if (r < 0) { if (errno != ENODATA && errno != ENOENT) return -errno; @@ -596,7 +596,7 @@ int LFNIndex::lfn_created(const vector &path, return 0; string full_path = get_full_path(path, mangled_name); string full_name = lfn_generate_object_name(hoid); - return do_setxattr(full_path.c_str(), LFN_ATTR.c_str(), + return do_setxattr(full_path.c_str(), get_lfn_attr().c_str(), full_name.c_str(), full_name.size()); } @@ -661,7 +661,7 @@ int LFNIndex::lfn_translate(const vector &path, // Get lfn_attr string full_path = get_full_path(path, short_name); char attr[PATH_MAX]; - int r = do_getxattr(full_path.c_str(), LFN_ATTR.c_str(), attr, sizeof(attr) - 1); + int r = do_getxattr(full_path.c_str(), get_lfn_attr().c_str(), attr, sizeof(attr) - 1); if (r < 0) return -errno; if (r < (int)sizeof(attr)) diff --git a/src/os/LFNIndex.h b/src/os/LFNIndex.h index 172239fa70727..e0321b45dbfed 100644 --- a/src/os/LFNIndex.h +++ b/src/os/LFNIndex.h @@ -79,12 +79,23 @@ class LFNIndex : public CollectionIndex { protected: const uint32_t index_version; +private: + string lfn_attribute; + public: /// Constructor LFNIndex( const char *base_path, ///< [in] path to Index root - int index_version) - : base_path(base_path), index_version(index_version) {} + uint32_t index_version) + : base_path(base_path), index_version(index_version) { + if (index_version == HASH_INDEX_TAG) { + lfn_attribute = LFN_ATTR; + } else { + char buf[100]; + snprintf(buf, sizeof(buf), "%d", index_version); + lfn_attribute = LFN_ATTR + string(buf); + } + } /// Virtual destructor virtual ~LFNIndex() {} @@ -311,6 +322,14 @@ protected: private: /* lfn translation functions */ + + /** + * Gets the version specific lfn attribute tag + */ + const string &get_lfn_attr() const { + return lfn_attribute; + } + /** * Gets the filename corresponsing to hoid in path. * -- 2.39.5