From e8cbdbb0ff0ba59f01845ddf540b13e9669be3eb Mon Sep 17 00:00:00 2001
From: Marcin Nowak <Marcin.Nowak@cern.ch>
Date: Thu, 8 Feb 2018 14:39:37 +0100
Subject: [PATCH] Switched to use Gaudi FileCatalog::removePFN

The attempted implementation in APR was not good


Former-commit-id: fcfc499c30313c4731e5f9bd1abae7db7078adb6
---
 .../FileCatalog/FileCatalog/IFileCatalog.h    | 12 ++---
 Database/APR/FileCatalog/src/IFileCatalog.cpp | 46 -------------------
 .../FileCatalog/utilities/FCaddReplica.cpp    |  9 +++-
 3 files changed, 13 insertions(+), 54 deletions(-)

diff --git a/Database/APR/FileCatalog/FileCatalog/IFileCatalog.h b/Database/APR/FileCatalog/FileCatalog/IFileCatalog.h
index 756b3f6bfd9..bc774adcde7 100644
--- a/Database/APR/FileCatalog/FileCatalog/IFileCatalog.h
+++ b/Database/APR/FileCatalog/FileCatalog/IFileCatalog.h
@@ -53,13 +53,13 @@ namespace pool {
      bool dirty() const  { return _fc->dirty(); }
 
      /// Get all FIDs 
-     void getFIDs( Strings& fids ) const { return _fc->getFID(fids); }
+     void getFIDs( Strings& fids ) const { _fc->getFID(fids); }
      
      /// Get all logical names for a given FID. Return pairs <LFN,FID>
-     void getLFNs( const std::string& fid, Files& files ) const { return _fc->getLFN(fid, files); }
+     void getLFNs( const std::string& fid, Files& files ) const { _fc->getLFN(fid, files); }
 
      /// Dump all PFNames of the catalog and their attributes associate to the FileID
-     void getPFNs( const std::string& fid, Files& files ) const { return _fc->getPFN(fid, files); }
+     void getPFNs( const std::string& fid, Files& files ) const { _fc->getPFN(fid, files); }
 
      /// Get the first PFN + filetype for the given FID
      void getFirstPFN( const std::string& fid, std::string& pfn, std::string& tech ) const;
@@ -84,16 +84,16 @@ namespace pool {
      //    bool existsFID( const std::string& fid ) const = 0;
 
      /// Delete FileID Node from the catalog
-     void deleteFID( const std::string& FileID ) { return _fc->deleteFID(FileID); }
+     void deleteFID( const std::string& FileID ) { _fc->deleteFID(FileID); }
 
      /// Delete PFN from the catalog (delete entire FID entry if it was the last PFN)
-     void deletePFN( const std::string& pfn );
+     void deletePFN( const std::string& pfn ) { _fc->deletePFN(pfn); }
 
      /// Register PFN, assign new FID if not given
      void registerPFN( const std::string& pfn, const std::string& ftype, std::string& fid );
 
      /// Rename PFN
-     void renamePFN( const std::string& pfn, const std::string& newpfn );
+     void renamePFN( const std::string& pfn, const std::string& newpfn ) { _fc->renamePFN(pfn, newpfn); }
 
      /// adding replica to an existing PFN
      void addReplicaPFN( const std::string& pfn, const std::string& replica_pfn );
diff --git a/Database/APR/FileCatalog/src/IFileCatalog.cpp b/Database/APR/FileCatalog/src/IFileCatalog.cpp
index 1a283ffd026..3830d077866 100644
--- a/Database/APR/FileCatalog/src/IFileCatalog.cpp
+++ b/Database/APR/FileCatalog/src/IFileCatalog.cpp
@@ -68,52 +68,6 @@ lookupFileByPFN( const std::string& pfn, std::string& fid, std::string& tech ) c
 }
    
 
-/// Delete PFN from the catalog (delete entire FID entry if it was the last PFN)
-void pool::IFileCatalog::
-deletePFN( const std::string& pfn )
-{
-   std::string fid = _fc->lookupPFN(pfn);
-   if( !fid.empty() ) {
-      Files     pfns, lfns;
-      getPFNs( fid, pfns );
-      getLFNs( fid, lfns );
-      deleteFID( fid );
-      for( const auto& p: pfns ) {
-         if( p.first != pfn )  registerPFN( p.first, p.second, fid );
-      }
-      for( const auto& l: lfns ) {
-         registerLFN( fid, l.first );
-      }
-   }
-}
-
-
-/// Rename PFN
-void pool::IFileCatalog::
-renamePFN( const std::string& pfn, const std::string& newpfn )
-{
-  std::string fid = _fc->lookupPFN(pfn);
-   if( !fid.empty() ) {
-      Files     pfns, lfns;
-      getPFNs( fid, pfns );
-      getLFNs( fid, lfns );
-      deleteFID( fid );
-      for( const auto& p: pfns ) {
-         if( p.first == pfn )  {
-            registerPFN( newpfn, p.second, fid );
-         } else {
-            registerPFN( p.first, p.second, fid );
-         }
-      }
-      for( const auto& l: lfns ) {
-         registerLFN( fid, l.first );
-      }
-   } else {
-      ATH_MSG_DEBUG("RenamePFN: PFN=" << pfn << " not found!");
-   }
-}
-
- 
 /// Register PFN, assign new FID if not given
 void pool::IFileCatalog::
 registerPFN( const std::string& pfn, const std::string& ftype, std::string& fid )
diff --git a/Database/APR/FileCatalog/utilities/FCaddReplica.cpp b/Database/APR/FileCatalog/utilities/FCaddReplica.cpp
index 483367a9741..c6d4591f703 100755
--- a/Database/APR/FileCatalog/utilities/FCaddReplica.cpp
+++ b/Database/APR/FileCatalog/utilities/FCaddReplica.cpp
@@ -9,6 +9,7 @@
 
 #include "FileCatalog/CommandLine.h"
 #include "FileCatalog/IFileCatalog.h"
+#include "FileCatalog/URIParser.h"
 #include "POOLCore/Exception.h"
 #include "POOLCore/SystemTools.h"
 #include <memory>
@@ -36,7 +37,9 @@ int main(int argc, char** argv)
     
     if( commands.Exists("u") ){
       myuri=commands.GetByName("u");
-    }    
+    } else {
+      myuri=SystemTools::GetEnvStr("POOL_CATALOG");
+    } 
     if( commands.Exists("p") ){
       mypfn=commands.GetByName("p");
     }
@@ -67,7 +70,9 @@ int main(int argc, char** argv)
   }
   try{
     std::auto_ptr<IFileCatalog> mycatalog(new IFileCatalog);
-    mycatalog->setWriteCatalog(myuri);
+    pool::URIParser p( myuri );
+    p.parse();
+    mycatalog->setWriteCatalog(p.contactstring());
     if( !mypfn.empty() ){
       mycatalog->connect();
       mycatalog->start();
-- 
GitLab