- Properly expands ~ characters in data.location
This commit is contained in:
14
html/README
Normal file
14
html/README
Normal file
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user