From b63e441bd6c83e00b306e751a33e1f00512e9776 Mon Sep 17 00:00:00 2001
From: Fabrice Le Goff <fabrice.le.goff@cern.ch>
Date: Wed, 12 Jul 2023 14:46:15 +0200
Subject: [PATCH] fixed: recreate original file when corrupted old info file

---
 Script/cs/Threads/ManagerThread.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Script/cs/Threads/ManagerThread.py b/Script/cs/Threads/ManagerThread.py
index 0d0b974..b85bc8a 100644
--- a/Script/cs/Threads/ManagerThread.py
+++ b/Script/cs/Threads/ManagerThread.py
@@ -327,6 +327,9 @@ class ManagerThread(threading.Thread):
         elif os.path.isfile(filename + Constants.problematic_ext): infofile = filename + Constants.problematic_ext
         elif os.path.isfile(filename + Constants.copied_ext): infofile = filename + Constants.copied_ext
 
+        # if no file exists, it defaults to TOBECOPIED
+        new_info_file_extension = Constants.tobecopied_ext
+
         if infofile:
             self.logger.debug('file: %s, reading info from existing helper file %s', filename, infofile)
             with open(infofile,'r') as info_file:
@@ -353,6 +356,8 @@ class ManagerThread(threading.Thread):
                         ': deleting infofile and getting metadata from scratch'
                         , infofile, remotedir, eosinstance)
                 os.remove(infofile)
+                # we need to recreate the same file
+                new_info_file_extension = os.path.splitext(infofile)[1]
             else:
                 self.logger.debug('filemetadata: remote dir = %s, eos instance = %s',
                         remotedir, eosinstance)
@@ -412,7 +417,7 @@ class ManagerThread(threading.Thread):
                             remotedir, eosinstance)
                     fmd = FileMetaData.FileMetaData(filename, remotedir, eosinstance,
                             mtime)
-                    fmd.writeToFile(Constants.tobecopied_ext, self.logger)
+                    fmd.writeToFile(new_info_file_extension, self.logger)
                     return fmd
 
         # Normal case
@@ -423,7 +428,7 @@ class ManagerThread(threading.Thread):
         self.logger.debug('normal case, filemetadata: remote dir = %s, eos instance = %s',
                 remotedir, eosinstance)
         fmd = FileMetaData.FileMetaData(filename, remotedir, eosinstance, mtime)
-        fmd.writeToFile(Constants.tobecopied_ext, self.logger)
+        fmd.writeToFile(new_info_file_extension, self.logger)
         return fmd
 
 
-- 
GitLab