From 3a391757d71eff4f41f5a05540e8833a666f327d Mon Sep 17 00:00:00 2001
From: Michael Davis <michael.davis@cern.ch>
Date: Thu, 19 Dec 2019 14:07:46 +0100
Subject: [PATCH] [admin] Adds Namespace.getPath() to dereference a diskId to a
 path

---
 xroot_plugins/CMakeLists.txt       |  2 +-
 xroot_plugins/Namespace.cpp        | 25 ++++++++++++++++++++++++
 xroot_plugins/Namespace.hpp        | 31 ++++++++++++++++++++++++++++++
 xroot_plugins/XrdCtaTapeFileLs.hpp |  4 +++-
 4 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 xroot_plugins/Namespace.cpp
 create mode 100644 xroot_plugins/Namespace.hpp

diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt
index 0ea81be879..9731072e26 100644
--- a/xroot_plugins/CMakeLists.txt
+++ b/xroot_plugins/CMakeLists.txt
@@ -35,7 +35,7 @@ include_directories(${CMAKE_BINARY_DIR}/eos_cta ${PROTOBUF3_INCLUDE_DIRS})
 #
 # XRootD SSI plugin for CTA Frontend
 #
-add_library(XrdSsiCta MODULE XrdSsiCtaServiceProvider.cpp XrdSsiCtaRequestProc.cpp XrdSsiCtaRequestMessage.cpp ../cmdline/CtaAdminCmdParse.cpp)
+add_library(XrdSsiCta MODULE XrdSsiCtaServiceProvider.cpp XrdSsiCtaRequestProc.cpp XrdSsiCtaRequestMessage.cpp ../cmdline/CtaAdminCmdParse.cpp Namespace.cpp)
 target_link_libraries(XrdSsiCta XrdSsi-4 XrdSsiLib XrdSsiPbEosCta ctascheduler ctacommon ctaobjectstore ctacatalogue)
 set_property (TARGET XrdSsiCta APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH})
 if (OCCI_SUPPORT)
diff --git a/xroot_plugins/Namespace.cpp b/xroot_plugins/Namespace.cpp
new file mode 100644
index 0000000000..aaff690917
--- /dev/null
+++ b/xroot_plugins/Namespace.cpp
@@ -0,0 +1,25 @@
+/*!
+ * @project        The CERN Tape Archive (CTA)
+ * @brief          CTA Frontend Tape Namespace query class
+ * @copyright      Copyright 2019 CERN
+ * @license        This program is free software: you can redistribute it and/or modify
+ *                 it under the terms of the GNU General Public License as published by
+ *                 the Free Software Foundation, either version 3 of the License, or
+ *                 (at your option) any later version.
+ *
+ *                 This program is distributed in the hope that it will be useful,
+ *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *                 GNU General Public License for more details.
+ *
+ *                 You should have received a copy of the GNU General Public License
+ *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string>
+#include <xroot_plugins/Namespace.hpp>
+
+
+std::string cta::Namespace::getPath(const std::string &diskFileId) {
+  return "/path/to/file/" + diskFileId;
+}
diff --git a/xroot_plugins/Namespace.hpp b/xroot_plugins/Namespace.hpp
new file mode 100644
index 0000000000..61d61a53c6
--- /dev/null
+++ b/xroot_plugins/Namespace.hpp
@@ -0,0 +1,31 @@
+/*!
+ * @project        The CERN Tape Archive (CTA)
+ * @brief          CTA Frontend Tape Namespace query class
+ * @copyright      Copyright 2019 CERN
+ * @license        This program is free software: you can redistribute it and/or modify
+ *                 it under the terms of the GNU General Public License as published by
+ *                 the Free Software Foundation, either version 3 of the License, or
+ *                 (at your option) any later version.
+ *
+ *                 This program is distributed in the hope that it will be useful,
+ *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *                 GNU General Public License for more details.
+ *
+ *                 You should have received a copy of the GNU General Public License
+ *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+namespace cta { 
+
+class Namespace
+{
+public:
+  std::string getPath(const std::string &diskFileId);
+
+//private:
+};
+
+} // namespace cta
diff --git a/xroot_plugins/XrdCtaTapeFileLs.hpp b/xroot_plugins/XrdCtaTapeFileLs.hpp
index 3563e177df..eb11778313 100644
--- a/xroot_plugins/XrdCtaTapeFileLs.hpp
+++ b/xroot_plugins/XrdCtaTapeFileLs.hpp
@@ -20,6 +20,7 @@
 
 #include <xroot_plugins/XrdCtaStream.hpp>
 #include <xroot_plugins/XrdSsiCtaRequestMessage.hpp>
+#include <xroot_plugins/Namespace.hpp>
 #include <common/checksum/ChecksumBlobSerDeser.hpp>
 
 
@@ -50,6 +51,7 @@ private:
   virtual int fillBuffer(XrdSsiPb::OStreamBuffer<Data> *streambuf);
 
   catalogue::ArchiveFileItor              m_tapeFileItor;                 //!< Iterator across files which have been archived
+  Namespace                               m_namespace;
 #if 0
   bool                                    m_isSummary;                       //!< Full listing or short summary?
   bool                                    m_isSummaryDone;                   //!< Summary has been sent
@@ -146,10 +148,10 @@ int TapeFileLsStream::fillBuffer(XrdSsiPb::OStreamBuffer<Data> *streambuf) {
       // Disk file
       auto df = record.mutable_tfls_item()->mutable_df();
       df->set_disk_id(archiveFile.diskFileId);
+      df->set_path(m_namespace.getPath(archiveFile.diskFileId));
       df->set_disk_instance(archiveFile.diskInstance);
       df->mutable_owner_id()->set_uid(archiveFile.diskFileInfo.owner_uid);
       df->mutable_owner_id()->set_gid(archiveFile.diskFileInfo.gid);
-      df->set_path(archiveFile.diskFileInfo.path);
 
       // Tape file
       auto tf = record.mutable_tfls_item()->mutable_tf();
-- 
GitLab