Skip to content
Snippets Groups Projects
Commit cd059e5a authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

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
parent a348ed2d
No related branches found
No related tags found
No related merge requests found
...@@ -435,16 +435,21 @@ void ConfigServiceImpl::configureLogging() ...@@ -435,16 +435,21 @@ void ConfigServiceImpl::configureLogging()
if (m_logFilePath.empty()) if (m_logFilePath.empty())
{ {
m_logFilePath = getUserPropertiesDir() + "mantid.log"; m_logFilePath = getUserPropertiesDir() + "mantid.log";
logpath.assign(m_logFilePath); // Check whether the file can be written. The Poco::File::canWrite method does not work
logpath = logpath.absolute(); // for files that don't exist, it throws an exception. It also can't be used to check for
if (Poco::File(logpath).canWrite() == false) // 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 // if we cannot write to the default directory then set use the system temp
logpath = Poco::Path::temp() + "mantid.log"; logpath = Poco::Path::temp() + "mantid.log";
} m_logFilePath = logpath.toString();
std::cerr << "Error writing to log file path to default location: \"" << m_logFilePath
m_logFilePath = logpath.toString(); << "\". Will use a system temp path instead: \"" << m_logFilePath << "\"" << std::endl;
}
else
fclose(fp);
} }
// Set the line in the configuration properties. // Set the line in the configuration properties.
// this'll be picked up by LoggingConfigurator (somehow) // this'll be picked up by LoggingConfigurator (somehow)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment