mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
- Properly expands ~ characters in data.location
This commit is contained in:
parent
ec8da0baaa
commit
2150642f9d
5 changed files with 44 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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&);
|
||||
|
|
27
src/util.cpp
27
src/util.cpp
|
@ -32,6 +32,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue