diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 8b0ec6a1..c0d3d2d1 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.41 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.42 2007-02-06 14:16:43 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -65,7 +65,12 @@ RclConfig::RclConfig(const string *argcnf) // Command line config name overrides environment if (argcnf && !argcnf->empty()) { - m_confdir = *argcnf; + m_confdir = path_absolute(*argcnf); + if (m_confdir.empty()) { + m_reason = + string("Cant turn [") + *argcnf + "] into absolute path"; + return; + } } else { const char *cp = getenv("RECOLL_CONFDIR"); if (cp) { diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 6b7819ca..04374f21 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: pathut.cpp,v 1.14 2006-12-23 13:07:21 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: pathut.cpp,v 1.15 2007-02-06 14:16:43 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -217,6 +217,21 @@ extern string path_tildexpand(const string &s) return o; } +extern std::string path_absolute(const std::string &is) +{ + if (is.length() == 0) + return is; + string s = is; + if (s[0] != '/') { + char buf[MAXPATHLEN]; + if (!getcwd(buf, MAXPATHLEN)) { + return ""; + } + s = path_cat(string(buf), s); + } + return s; +} + #include extern std::string path_canon(const std::string &is) { diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 51c200f9..97c4955c 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -16,7 +16,7 @@ */ #ifndef _PATHUT_H_INCLUDED_ #define _PATHUT_H_INCLUDED_ -/* @(#$Id: pathut.h,v 1.11 2006-12-16 15:31:51 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: pathut.h,v 1.12 2007-02-06 14:16:43 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -41,7 +41,10 @@ extern string path_getfather(const string &s); extern string path_home(); /// Expand ~ at the beginning of string extern string path_tildexpand(const string &s); -/// Clean up path by removing duplicated / and resolving ../ +/// Use getcwd() to make absolute path if needed. Beware: ***this can fail*** +/// we return an empty path in this case. +extern string path_absolute(const string &s); +/// Clean up path by removing duplicated / and resolving ../ + make it absolute extern string path_canon(const string &s); /// Use glob(3) to return a list of file names matching pattern inside dir extern list path_dirglob(const string &dir,