From 42e0982177e971357889b07fa0a48f3c1a620487 Mon Sep 17 00:00:00 2001
From: Daniele Kruse <dkruse@cern.ch>
Date: Mon, 10 Aug 2015 17:44:37 +0200
Subject: [PATCH] Added the backend location path parameter to castor.conf and
 passed it to the backendVFS

---
 objectstore/BackendVFS.cpp                           | 12 ++++++------
 .../castor/tape/tapeserver/daemon/ProcessForker.cpp  |  4 +++-
 .../tape/tapeserver/daemon/TapeDaemonConfig.cpp      |  1 +
 .../tape/tapeserver/daemon/TapeDaemonConfig.hpp      |  5 +++++
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/objectstore/BackendVFS.cpp b/objectstore/BackendVFS.cpp
index e3b92ec87b..f75ac995fe 100644
--- a/objectstore/BackendVFS.cpp
+++ b/objectstore/BackendVFS.cpp
@@ -27,7 +27,8 @@
 #include <stdio.h>
 #include <memory>
 #include <unistd.h>
-
+#include <sys/socket.h>
+#include <sys/stat.h>
 
 
 namespace cta { namespace objectstore {
@@ -161,10 +162,9 @@ void BackendVFS::remove(std::string name) {
 
 bool BackendVFS::exists(std::string name) {
   std::string path = m_root + "/" + name;
-  std::string lockPath = m_root + "/." + name + ".lock";
-  if (::access(path.c_str(), F_OK) || ::access(lockPath.c_str(), F_OK))
-    return false;
-  return true;
+  std::string lockPath = m_root + "/." + name + ".lock";  
+  struct stat buffer;   
+  return (stat(path.c_str(), &buffer)==0 && stat(lockPath.c_str(), &buffer)==0);
 }
 
 
@@ -186,7 +186,7 @@ BackendVFS::ScopedLock * BackendVFS::lockHelper(
   std::string name, int type) {
   std::string path = m_root + "/." + name + ".lock";
   std::unique_ptr<ScopedLock> ret(new ScopedLock);
-  ret->set(::open(path.c_str(), O_RDONLY, S_IRWXU));
+  ret->set(::open(path.c_str(), O_RDONLY));
   cta::exception::Errnum::throwOnMinusOne(ret->m_fd,
       "In BackendStoreVFS::lockHelper, failed to open the lock file.");
   cta::exception::Errnum::throwOnMinusOne(::flock(ret->m_fd, LOCK_EX),
diff --git a/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp b/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
index 9c3d7ef12d..854373d471 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
@@ -556,7 +556,9 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
     zmqContext.get());
   
   /************BEGIN: boilerplate code to prepare the objectstoreDB object**************/
-  cta::objectstore::BackendVFS g_backend;
+  cta::objectstore::BackendVFS g_backend(m_config.objectStoreBackendPath);
+      // Make sure we will not delete the contents of objectstore when deleting the object
+      g_backend.noDeleteOnExit();
 
   class BackendPopulator {
   public:
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
index 57bbe464b2..2040ad1269 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
@@ -53,6 +53,7 @@ castor::tape::tapeserver::daemon::TapeDaemonConfig
   config.cupvHost = castorConf.getConfEntString("UPV" , "HOST", log);
   config.vdqmHost = castorConf.getConfEntString("VDQM", "HOST", log);
   config.vmgrHost = castorConf.getConfEntString("VMGR", "HOST", log);
+  config.objectStoreBackendPath = castorConf.getConfEntString("TapeServer", "ObjectStoreBackendPath", log);
   config.rmcPort = castorConf.getConfEntInt("RMC", "PORT",
     (unsigned short)RMC_PORT, log);
   config.rmcMaxRqstAttempts = castorConf.getConfEntInt("RMC",
diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
index 38e4f5c375..749a92ec98 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
@@ -46,6 +46,11 @@ struct TapeDaemonConfig {
    * The CASTOR configuration parameters used by the Catalogue.
    */
   CatalogueConfig catalogueConfig;
+  
+  /**
+   * This is the path to the objectstore backend
+   */
+  std::string objectStoreBackendPath;
 
   /**
    * The network name of the host on which the cupv daemon is running.
-- 
GitLab