From cd059e5acd2aaaa4aa8817ec807241d8f4eadf6a Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Fri, 4 Oct 2013 15:40:01 +0100
Subject: [PATCH] Check for writability of log path more verbosely.

As commented in the code the Poco & Windows APIs are not reliable enough
to check for write permissions on a directory.
Refs #8080
---
 .../Framework/Kernel/src/ConfigService.cpp    | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
index ce2b1e105f6..9cfcbff8571 100644
--- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
@@ -435,16 +435,21 @@ void ConfigServiceImpl::configureLogging()
     if (m_logFilePath.empty())
     {
       m_logFilePath = getUserPropertiesDir() + "mantid.log";
-      logpath.assign(m_logFilePath);
-      logpath = logpath.absolute();
-      if (Poco::File(logpath).canWrite() == false)
+      // Check whether the file can be written. The Poco::File::canWrite method does not work
+      // for files that don't exist, it throws an exception. It also can't be used to check for
+      // directory access as the Windows API doesn't return this information correctly for
+      // directories.
+      FILE *fp = fopen(m_logFilePath.c_str(), "a+");
+      if (!fp)
       {
           // if we cannot write to the default directory then set use the system temp
           logpath = Poco::Path::temp() + "mantid.log";
-      }
-
-      m_logFilePath = logpath.toString();
-
+          m_logFilePath = logpath.toString();
+          std::cerr << "Error writing to log file path to default location: \"" << m_logFilePath
+                    << "\". Will use a system temp path instead: \"" << m_logFilePath << "\"" << std::endl;
+       }
+       else
+         fclose(fp);
     }
     // Set the line in the configuration properties.
     //  this'll be picked up by LoggingConfigurator (somehow)
-- 
GitLab