From 2150642f9d39996844fa547d9a95b283f16c8962 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 9 Jul 2008 22:56:39 -0400 Subject: [PATCH] - Properly expands ~ characters in data.location --- html/README | 14 ++++++++++++++ src/command.cpp | 2 +- src/task.cpp | 2 +- src/task.h | 1 + src/util.cpp | 27 +++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 html/README diff --git a/html/README b/html/README new file mode 100644 index 000000000..ecd393fc9 --- /dev/null +++ b/html/README @@ -0,0 +1,14 @@ +Documentation Restructuring + high level pages + download + previous verisons + tutorial + recurrence + priorities + subprojects + tags + + + need page banner + need task link off beckinghma.net + diff --git a/src/command.cpp b/src/command.cpp index d92e35c22..7f2a2bcee 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -279,7 +279,7 @@ void handleVersion (Config& conf) "file." << std::endl; - if (access (conf.get ("data.location").c_str (), X_OK)) + if (access (expandPath (conf.get ("data.location")).c_str (), X_OK)) std::cout << "Configuration error: data.location contains a directory name" " that doesn't exist, or is unreadable." << std::endl; diff --git a/src/task.cpp b/src/task.cpp index ba48c472e..183361887 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -286,7 +286,7 @@ int main (int argc, char** argv) } TDB tdb; - tdb.dataDirectory (conf.get ("data.location")); + tdb.dataDirectory (expandPath (conf.get ("data.location"))); // Log commands, if desired. if (conf.get ("command.logging") == "on") diff --git a/src/task.h b/src/task.h index e6467fd54..9060c7dde 100644 --- a/src/task.h +++ b/src/task.h @@ -119,6 +119,7 @@ std::string formatSeconds (time_t); const std::string uuid (); const char* optionalBlankLine (Config&); int convertDuration (std::string&); +std::string expandPath (const std::string&); // rules.cpp void initializeColorRules (Config&); diff --git a/src/util.cpp b/src/util.cpp index 99ed46752..e96229f9b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "Date.h" #include "Table.h" #include "task.h" @@ -304,3 +305,29 @@ int convertDuration (std::string& input) } //////////////////////////////////////////////////////////////////////////////// +std::string expandPath (const std::string& in) +{ + std::string copy = in; + unsigned int tilde; + + if ((tilde = copy.find ("~/")) != std::string::npos) + { + struct passwd* pw = getpwuid (getuid ()); + copy.replace (tilde, 1, pw->pw_dir); + } + else if ((tilde = copy.find ("~")) != std::string::npos) + { + unsigned int slash; + if ((slash = copy.find ("/", tilde)) != std::string::npos) + { + std::string name = copy.substr (tilde + 1, slash - tilde - 1); + struct passwd* pw = getpwnam (name.c_str ()); + if (pw) + copy.replace (tilde, slash - tilde, pw->pw_dir); + } + } + + return copy; +} + +////////////////////////////////////////////////////////////////////////////////