Store original working directory before changing, for later turning user args into absolute paths
This commit is contained in:
parent
77cba9d0b3
commit
e77c510dfe
@ -23,6 +23,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -60,6 +61,7 @@ typedef pair<int,int> RclPII;
|
|||||||
bool o_index_stripchars = true;
|
bool o_index_stripchars = true;
|
||||||
|
|
||||||
string RclConfig::o_localecharset;
|
string RclConfig::o_localecharset;
|
||||||
|
string RclConfig::o_origcwd;
|
||||||
|
|
||||||
bool ParamStale::needrecompute()
|
bool ParamStale::needrecompute()
|
||||||
{
|
{
|
||||||
@ -118,6 +120,16 @@ bool RclConfig::isDefaultConfig() const
|
|||||||
RclConfig::RclConfig(const string *argcnf)
|
RclConfig::RclConfig(const string *argcnf)
|
||||||
{
|
{
|
||||||
zeroMe();
|
zeroMe();
|
||||||
|
|
||||||
|
if (o_origcwd.empty()) {
|
||||||
|
char buf[MAXPATHLEN];
|
||||||
|
if (getcwd(buf, MAXPATHLEN)) {
|
||||||
|
o_origcwd = string(buf);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "recollxx: can't retrieve current working directory: relative path translations will fail\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compute our data dir name, typically /usr/local/share/recoll
|
// Compute our data dir name, typically /usr/local/share/recoll
|
||||||
const char *cdatadir = getenv("RECOLL_DATADIR");
|
const char *cdatadir = getenv("RECOLL_DATADIR");
|
||||||
if (cdatadir == 0) {
|
if (cdatadir == 0) {
|
||||||
|
|||||||
@ -257,6 +257,11 @@ class RclConfig {
|
|||||||
call it after primary init */
|
call it after primary init */
|
||||||
void initThrConf();
|
void initThrConf();
|
||||||
|
|
||||||
|
const string& getOrigCwd()
|
||||||
|
{
|
||||||
|
return o_origcwd;
|
||||||
|
}
|
||||||
|
|
||||||
~RclConfig() {
|
~RclConfig() {
|
||||||
freeAll();
|
freeAll();
|
||||||
}
|
}
|
||||||
@ -302,6 +307,10 @@ class RclConfig {
|
|||||||
ParamStale m_skpnstate;
|
ParamStale m_skpnstate;
|
||||||
vector<string> m_skpnlist;
|
vector<string> m_skpnlist;
|
||||||
|
|
||||||
|
// Original current working directory. Set once at init before we do any
|
||||||
|
// chdir'ing and used for converting user args to absolute paths.
|
||||||
|
static string o_origcwd;
|
||||||
|
|
||||||
// Parameters auto-fetched on setkeydir
|
// Parameters auto-fetched on setkeydir
|
||||||
string m_defcharset;
|
string m_defcharset;
|
||||||
static string o_localecharset;
|
static string o_localecharset;
|
||||||
|
|||||||
@ -157,9 +157,10 @@ bool ConfIndexer::index(bool resetbefore, ixType typestorun)
|
|||||||
bool ConfIndexer::indexFiles(list<string>& ifiles, IxFlag flag)
|
bool ConfIndexer::indexFiles(list<string>& ifiles, IxFlag flag)
|
||||||
{
|
{
|
||||||
list<string> myfiles;
|
list<string> myfiles;
|
||||||
|
string origcwd = m_config->getOrigCwd();
|
||||||
for (list<string>::const_iterator it = ifiles.begin();
|
for (list<string>::const_iterator it = ifiles.begin();
|
||||||
it != ifiles.end(); it++) {
|
it != ifiles.end(); it++) {
|
||||||
myfiles.push_back(path_canon(*it));
|
myfiles.push_back(path_canon(*it, &origcwd));
|
||||||
}
|
}
|
||||||
myfiles.sort();
|
myfiles.sort();
|
||||||
|
|
||||||
@ -239,9 +240,10 @@ bool ConfIndexer::updateDocs(std::vector<Rcl::Doc> &docs, IxFlag flag)
|
|||||||
bool ConfIndexer::purgeFiles(std::list<string> &files)
|
bool ConfIndexer::purgeFiles(std::list<string> &files)
|
||||||
{
|
{
|
||||||
list<string> myfiles;
|
list<string> myfiles;
|
||||||
|
string origcwd = m_config->getOrigCwd();
|
||||||
for (list<string>::const_iterator it = files.begin();
|
for (list<string>::const_iterator it = files.begin();
|
||||||
it != files.end(); it++) {
|
it != files.end(); it++) {
|
||||||
myfiles.push_back(path_canon(*it));
|
myfiles.push_back(path_canon(*it, &origcwd));
|
||||||
}
|
}
|
||||||
myfiles.sort();
|
myfiles.sort();
|
||||||
|
|
||||||
|
|||||||
@ -335,17 +335,22 @@ extern string path_absolute(const string &is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include <smallut.h>
|
#include <smallut.h>
|
||||||
extern string path_canon(const string &is)
|
extern string path_canon(const string &is, const string* cwd)
|
||||||
{
|
{
|
||||||
if (is.length() == 0)
|
if (is.length() == 0)
|
||||||
return is;
|
return is;
|
||||||
string s = is;
|
string s = is;
|
||||||
if (s[0] != '/') {
|
if (s[0] != '/') {
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
if (!getcwd(buf, MAXPATHLEN)) {
|
const char *cwdp = buf;
|
||||||
return string();
|
if (cwd) {
|
||||||
|
cwdp = cwd->c_str();
|
||||||
|
} else {
|
||||||
|
if (!getcwd(buf, MAXPATHLEN)) {
|
||||||
|
return string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s = path_cat(string(buf), s);
|
s = path_cat(string(cwdp), s);
|
||||||
}
|
}
|
||||||
vector<string> elems;
|
vector<string> elems;
|
||||||
stringToTokens(s, elems, "/");
|
stringToTokens(s, elems, "/");
|
||||||
|
|||||||
@ -45,7 +45,7 @@ extern std::string path_tildexpand(const std::string &s);
|
|||||||
/// we return an empty path in this case.
|
/// we return an empty path in this case.
|
||||||
extern std::string path_absolute(const std::string &s);
|
extern std::string path_absolute(const std::string &s);
|
||||||
/// Clean up path by removing duplicated / and resolving ../ + make it absolute
|
/// Clean up path by removing duplicated / and resolving ../ + make it absolute
|
||||||
extern std::string path_canon(const std::string &s);
|
extern std::string path_canon(const std::string &s, const std::string *cwd=0);
|
||||||
/// Use glob(3) to return the file names matching pattern inside dir
|
/// Use glob(3) to return the file names matching pattern inside dir
|
||||||
extern std::vector<std::string> path_dirglob(const std::string &dir,
|
extern std::vector<std::string> path_dirglob(const std::string &dir,
|
||||||
const std::string pattern);
|
const std::string pattern);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user