From be893f05511c5a967ce790672ce52fce8697b161 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 3 Mar 2016 08:45:34 -0500 Subject: [PATCH] init: Added determination of database location --- src/init.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 10b195cc..ceaacfb1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -53,7 +53,32 @@ bool lightweightVersionCheck (int argc, const char** argv) //////////////////////////////////////////////////////////////////////////////// void initializeData (Configuration& configuration, Database& database) { - // TODO Load configuration ~/.timewrc || $TIMEWRC. + // The $TIMEWARRIORDB environment variable overrides the default value of + // ~/.timewarrior‥ + Directory dbLocation; + char* override = getenv ("TIMEWARRIORDB"); + if (override) + { + std::cout << "# TIMEWARRIORDB " << override << "\n"; + dbLocation = Directory (override); + } + else + { + dbLocation = Directory ("~/.timewarrior"); + std::cout << "# Using default DB location " << dbLocation._data << "\n"; + } + + // TODO If dbLocation does not exist, ask whether it should be created. + // TODO IF dbLocation exists, but is not readable/writable/executable, error. + + // TODO Load the configuration data. + + // This value is not written out to disk, as there would be no point. Having + // located the config file, the 'db' location is already known. This is just + // for subsequent internal use. + configuration.set ("db", dbLocation._data); + std::cout << "# rc.db=" << configuration.get ("db") << "\n"; + // TODO Init database (no data read). std::cout << "# Configuration\n";