recollindex -r: make path args absolute using the original working directory, not the rundir (tmp)
This commit is contained in:
parent
476a3ba743
commit
5915dd6cea
@ -585,6 +585,10 @@ static vector<string> fileToArgs(const string& fn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Working directory before we change: it's simpler to change early
|
||||||
|
// but some options need the original for computing absolute paths.
|
||||||
|
static std::string orig_cwd;
|
||||||
|
|
||||||
// A bit of history: it's difficult to pass non-ASCII parameters
|
// A bit of history: it's difficult to pass non-ASCII parameters
|
||||||
// (e.g. path names) on the command line under Windows without using
|
// (e.g. path names) on the command line under Windows without using
|
||||||
// Unicode. It was first thought possible to use a temporary file to
|
// Unicode. It was first thought possible to use a temporary file to
|
||||||
@ -725,6 +729,7 @@ int main(int argc, char *argv[])
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
orig_cwd = path_cwd();
|
||||||
string rundir;
|
string rundir;
|
||||||
config->getConfParam("idxrundir", rundir);
|
config->getConfParam("idxrundir", rundir);
|
||||||
if (!rundir.empty()) {
|
if (!rundir.empty()) {
|
||||||
@ -775,6 +780,7 @@ int main(int argc, char *argv[])
|
|||||||
if (aremain != 1)
|
if (aremain != 1)
|
||||||
Usage();
|
Usage();
|
||||||
string top = args[argidx++]; aremain--;
|
string top = args[argidx++]; aremain--;
|
||||||
|
top = path_canon(top, &orig_cwd);
|
||||||
bool status = recursive_index(config, top, selpatterns);
|
bool status = recursive_index(config, top, selpatterns);
|
||||||
if (confindexer && !confindexer->getReason().empty()) {
|
if (confindexer && !confindexer->getReason().empty()) {
|
||||||
addIdxReason("indexer", confindexer->getReason());
|
addIdxReason("indexer", confindexer->getReason());
|
||||||
|
|||||||
@ -756,11 +756,7 @@ string path_absolute(const string& is)
|
|||||||
path_slashize(s);
|
path_slashize(s);
|
||||||
#endif
|
#endif
|
||||||
if (!path_isabsolute(s)) {
|
if (!path_isabsolute(s)) {
|
||||||
char buf[MAXPATHLEN];
|
s = path_cat(path_cwd(), s);
|
||||||
if (!getcwd(buf, MAXPATHLEN)) {
|
|
||||||
return string();
|
|
||||||
}
|
|
||||||
s = path_cat(string(buf), s);
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
path_slashize(s);
|
path_slashize(s);
|
||||||
#endif
|
#endif
|
||||||
@ -783,16 +779,11 @@ string path_canon(const string& is, const string* cwd)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!path_isabsolute(s)) {
|
if (!path_isabsolute(s)) {
|
||||||
char buf[MAXPATHLEN];
|
|
||||||
const char *cwdp = buf;
|
|
||||||
if (cwd) {
|
if (cwd) {
|
||||||
cwdp = cwd->c_str();
|
s = path_cat(*cwd, s);
|
||||||
} else {
|
} else {
|
||||||
if (!getcwd(buf, MAXPATHLEN)) {
|
s = path_cat(path_cwd(), s);
|
||||||
return string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s = path_cat(string(cwdp), s);
|
|
||||||
}
|
}
|
||||||
vector<string> elems;
|
vector<string> elems;
|
||||||
stringToTokens(s, elems, "/");
|
stringToTokens(s, elems, "/");
|
||||||
@ -871,6 +862,27 @@ bool path_chdir(const std::string& path)
|
|||||||
return CHDIR(syspath) == 0;
|
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)
|
bool path_unlink(const std::string& path)
|
||||||
{
|
{
|
||||||
SYSPATH(path, syspath);
|
SYSPATH(path, syspath);
|
||||||
|
|||||||
@ -135,6 +135,7 @@ extern bool path_makepath(const std::string& path, int mode);
|
|||||||
|
|
||||||
///
|
///
|
||||||
extern bool path_chdir(const std::string& path);
|
extern bool path_chdir(const std::string& path);
|
||||||
|
extern std::string path_cwd();
|
||||||
extern bool path_unlink(const std::string& path);
|
extern bool path_unlink(const std::string& path);
|
||||||
|
|
||||||
/* Open file, trying to do the right thing with non-ASCII paths on
|
/* Open file, trying to do the right thing with non-ASCII paths on
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user