From db1c9d2543ac0baa69a62b11429e317d6b6ecb2b Mon Sep 17 00:00:00 2001
From: Sylvia Biscoveanu <sylvia.biscoveanu@ligo.org>
Date: Mon, 18 May 2020 17:09:45 -0500
Subject: [PATCH] Fix multinest temporary directory functionality

---
 bilby/core/sampler/pymultinest.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/bilby/core/sampler/pymultinest.py b/bilby/core/sampler/pymultinest.py
index 55c3ac1af..055d4e14a 100644
--- a/bilby/core/sampler/pymultinest.py
+++ b/bilby/core/sampler/pymultinest.py
@@ -181,11 +181,15 @@ class Pymultinest(NestedSampler):
                 self.outputfiles_basename, self.temporary_outputfiles_basename
             )
         )
-        if os.path.islink(self.outputfiles_basename.strip("/")):
-            os.unlink(self.outputfiles_basename.strip("/"))
-        elif os.path.isdir(self.outputfiles_basename):
-            shutil.rmtree(self.outputfiles_basename, ignore_errors=True)
-        shutil.move(self.temporary_outputfiles_basename, self.outputfiles_basename)
+        if self.outputfiles_basename.endswith('/'):
+            outputfiles_basename_stripped = self.outputfiles_basename[:-1]
+        else:
+            outputfiles_basename_stripped = self.outputfiles_basename
+        if os.path.islink(outputfiles_basename_stripped):
+            os.unlink(outputfiles_basename_stripped)
+        elif os.path.isdir(outputfiles_basename_stripped):
+            shutil.rmtree(outputfiles_basename_stripped)
+        shutil.move(self.temporary_outputfiles_basename, outputfiles_basename_stripped)
 
     def run_sampler(self):
         import pymultinest
-- 
GitLab