init: Moved permissions check earlier in the processing

This commit is contained in:
Paul Beckingham 2016-04-17 08:13:02 -04:00
parent 7db6f68b92
commit 726ac35a44

View file

@ -113,6 +113,15 @@ void initializeDataAndRules (
char* override = getenv ("TIMEWARRIORDB");
dbLocation = Directory (override ? override : "~/.timewarrior");
// If dbLocation exists, but is not readable/writable/executable, error.
if (dbLocation.exists () &&
(! dbLocation.readable () ||
! dbLocation.writable () ||
! dbLocation.executable ()))
{
throw format ("Database is not readable at '{1}'", dbLocation._data);
}
// If dbLocation does not exist, ask whether it should be created.
bool shinyNewDatabase = false;
if (! dbLocation.exists () &&
@ -134,15 +143,6 @@ void initializeDataAndRules (
if (! data.exists ())
data.create (0700);
// If dbLocation exists, but is not readable/writable/executable, error.
if (dbLocation.exists () &&
(! dbLocation.readable () ||
! dbLocation.writable () ||
! dbLocation.executable ()))
{
throw format ("Database is not readable at '{1}'", dbLocation._data);
}
// Load the configuration data.
File configFile (dbLocation);
configFile += "timewarrior.cfg";