From e60e02bdcec91ec03ab94a9849d1059938e17fe1 Mon Sep 17 00:00:00 2001
From: Michael McWilliam <mimc@dtu.dk>
Date: Tue, 12 Mar 2019 16:31:53 +0100
Subject: [PATCH] Fixed bugs with accompaning files

---
 wetb/hawc2/hawc2_simulation.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/wetb/hawc2/hawc2_simulation.py b/wetb/hawc2/hawc2_simulation.py
index 50e8f3d..448e006 100644
--- a/wetb/hawc2/hawc2_simulation.py
+++ b/wetb/hawc2/hawc2_simulation.py
@@ -271,15 +271,19 @@ class Hawc2_Simulation(object):
             self.accompanying_files = list()
             self.accompanying_destinations = list()
         # test if it is accessible from the script PWD
-        if not os.path.isfile(accompanying_file) and not os.path.isdir(accompanying_file):
+        if (not os.path.isfile(accompanying_file) and not os.path.islink(accompanying_file) and not os.path.isdir(accompanying_file)) or not accompanying_file.startswith(self.source_directory):
             accompanying_file=os.path.join(self.source_directory,accompanying_file)
-            if not os.path.isfile(accompanying_file) and not os.path.isdir(accompanying_file):
+            # Otherwise, see if we can access within the source directory
+            if not os.path.isfile(accompanying_file) and not os.path.islink(accompanying_file) and not os.path.isdir(accompanying_file):
                 raise ValueError('The accompanying file "%s" must be contained within the directory of the HTC file, or one of the sub-directories'%(accompanying_file))
-        else:
-            accompanying_file=os.path.abspath(os.path.realpath(accompanying_file))
+        # If the file is not in the source directory, then we cannot figure out the destination
         if not accompanying_file.startswith(self.source_directory):
             raise ValueError('The accompanying file must be contained within the directory of the HTC file, or one of the sub-directories. file: {} not found'.format(accompanying_file))
+        # Get the destination that would be used relative from the source directory
         destination=accompanying_file[len(self.source_directory)+1:]
+        # set the source for the file to it's absolute real path
+        accompanying_file=os.path.abspath(os.path.realpath(accompanying_file))
+
         self.accompanying_files.append(accompanying_file)
         self.accompanying_destinations.append(destination)
 
-- 
GitLab