From 5e4f70365b2848d0cf8eb537f28b61a4efa9d2f3 Mon Sep 17 00:00:00 2001
From: Samuel Jones <samjones714@gmail.com>
Date: Mon, 12 Nov 2018 10:55:31 +0000
Subject: [PATCH] Re #23739 Handle empty files and non-PID folders/files

---
 MantidPlot/src/ProjectRecovery.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp
index f4ed7f4bb16..3e5de2c27ab 100644
--- a/MantidPlot/src/ProjectRecovery.cpp
+++ b/MantidPlot/src/ProjectRecovery.cpp
@@ -145,9 +145,14 @@ std::vector<int> orderProcessIDs(std::vector<Poco::Path> paths) {
               // Last modified is first!
               return a1.getLastModified() > b1.getLastModified();
             });
-
   for (auto c : paths) {
-    returnValues.emplace_back(std::stoi(c.directory(c.depth() - 1)));
+    try {
+      returnValues.emplace_back(std::stoi(c.directory(c.depth() - 1)));
+    } catch (std::invalid_argument &e) {
+      // The folder or file here is not a number (So shouldn't exist) so delete
+      // it recursively
+      Poco::File(c).remove(true);
+    }
   }
   return returnValues;
 }
@@ -794,6 +799,12 @@ void ProjectRecovery::repairCheckpointDirectory() {
                 "mantid has been unable to successfully handle repair so "
                 "checkpoints may be invalid");
   }
+
+  if (vectorToDelete.size() > 0) {
+    g_log.information("Project Recovery: A repair of the checkpoint directory "
+                      "has been perfomed");
+  }
+
   bool recurse = true;
   for (auto c : vectorToDelete) {
     Poco::File(c).remove(recurse);
-- 
GitLab