recollindex -r: make path args absolute using the original working directory, not the rundir (tmp)

This commit is contained in:
Jean-Francois Dockes
2020-07-13 10:47:32 +02:00
parent 476a3ba743
commit 5915dd6cea
3 changed files with 31 additions and 12 deletions
+24 -12
View File
@@ -756,11 +756,7 @@ string path_absolute(const string& is)
path_slashize(s);
#endif
if (!path_isabsolute(s)) {
char buf[MAXPATHLEN];
if (!getcwd(buf, MAXPATHLEN)) {
return string();
}
s = path_cat(string(buf), s);
s = path_cat(path_cwd(), s);
#ifdef _WIN32
path_slashize(s);
#endif
@@ -783,16 +779,11 @@ string path_canon(const string& is, const string* cwd)
#endif
if (!path_isabsolute(s)) {
char buf[MAXPATHLEN];
const char *cwdp = buf;
if (cwd) {
cwdp = cwd->c_str();
s = path_cat(*cwd, s);
} else {
if (!getcwd(buf, MAXPATHLEN)) {
return string();
}
s = path_cat(path_cwd(), s);
}
s = path_cat(string(cwdp), s);
}
vector<string> elems;
stringToTokens(s, elems, "/");
@@ -871,6 +862,27 @@ bool path_chdir(const std::string& path)
return CHDIR(syspath) == 0;
}
std::string path_cwd()
{
#ifdef _WIN32
wchar_t *wd = _wgetcwd(nullptr, 0);
if (nullptr == wd) {
return std::string();
}
string sdname;
wchartoutf8(wd, sdname);
free(wd);
path_slashize(sdname);
return sdname;
#else
char wd[MAXPATHLEN+1];
if (nullptr == getcwd(wd, MAXPATHLEN+1)) {
return string();
}
return wd;
#endif
}
bool path_unlink(const std::string& path)
{
SYSPATH(path, syspath);
+1
View File
@@ -135,6 +135,7 @@ extern bool path_makepath(const std::string& path, int mode);
///
extern bool path_chdir(const std::string& path);
extern std::string path_cwd();
extern bool path_unlink(const std::string& path);
/* Open file, trying to do the right thing with non-ASCII paths on