From bf202bab2900d36902905c3eda438ca058c89063 Mon Sep 17 00:00:00 2001
From: Conor Finn <conor.finn@stfc.ac.uk>
Date: Fri, 20 Mar 2020 15:34:58 +0000
Subject: [PATCH] RE #28360 Fix logs not saving if directory exists already

Needed to add checks around makedirs(), throws an error if the directory
already exists.
---
 .../engineering_diffraction/tabs/focus/model.py   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py
index befe2aea0b9..6cee459144d 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py
@@ -193,15 +193,16 @@ class FocusModel(object):
             except ValueError:
                 logger.information(f"Could not convert {name} to a numerical value. It will not be included in the "
                                    f"sample logs output file.")
-
-        makedirs(path.join(path_handling.get_output_path(), "Focus"))
-        output_path = path.join(path_handling.get_output_path(), "Focus",
-                                (instrument + "_" + run_number + "_sample_logs.csv"))
+        focus_dir = path.join(path_handling.get_output_path(), "Focus")
+        if not path.exists(focus_dir):
+            makedirs(focus_dir)
+        output_path = path.join(focus_dir, (instrument + "_" + run_number + "_sample_logs.csv"))
         write_to_file()
         if rb_num:
-            makedirs(path.join(path_handling.get_output_path(), "User", rb_num, "Focus"))
-            output_path = path.join(path_handling.get_output_path(), "User", rb_num, "Focus",
-                                    (instrument + "_" + run_number + "_sample_logs.csv"))
+            focus_user_dir = path.join(path_handling.get_output_path(), "User", rb_num, "Focus")
+            if not path.exists(focus_user_dir):
+                makedirs(focus_user_dir)
+            output_path = path.join(focus_user_dir, (instrument + "_" + run_number + "_sample_logs.csv"))
             write_to_file()
 
     @staticmethod
-- 
GitLab