Windows recollindex: use wmain to accept unicode command line args.
This commit is contained in:
parent
0d375d0b31
commit
cb3a59f88f
@ -548,19 +548,29 @@ static void flushIdxReasons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define WARGTOSTRING(w) wchartoutf8(w)
|
||||||
|
static vector<string> argstovector(int argc, wchar_t **argv)
|
||||||
|
#else
|
||||||
|
#define WARGTOSTRING(w) (w)
|
||||||
static vector<string> argstovector(int argc, char **argv)
|
static vector<string> argstovector(int argc, char **argv)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
thisprog = path_absolute(WARGTOSTRING(argv[0]));
|
||||||
|
argc--; argv++;
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
args.push_back(argv[i]);
|
args.push_back(WARGTOSTRING(argv[i]));
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
static vector<string> fileToArgs(const string& fn)
|
static vector<string> fileToArgs(const string& fn)
|
||||||
{
|
{
|
||||||
string reason, data;
|
string reason, data;
|
||||||
if (!file_to_string(fn, data, &reason)) {
|
if (!file_to_string(fn, data, &reason)) {
|
||||||
cerr << "Failed reading args file " << fn << " errno " << errno << "\n";
|
std::cerr << "Failed reading args file " << fn << " reason " <<
|
||||||
|
reason << "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
@ -568,12 +578,19 @@ static vector<string> fileToArgs(const string& fn)
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
// A bit of history: it's difficult to pass non-ascii parameters
|
||||||
|
// (e.g. path names) on the command line under Windows without using
|
||||||
|
// Unicode. It was first thought possible to use a temporary file to
|
||||||
|
// hold the args, and make sure that the path for this would be ASCII,
|
||||||
|
// based on using shortpath(). Unfortunately, this does not work in
|
||||||
|
// all cases, so the second change was to use wmain(), but the
|
||||||
|
// now largely redundant args-in-file passing trick was kept anyway.
|
||||||
|
#ifdef _WIN32
|
||||||
|
int wmain(int argc, wchar_t *argv[])
|
||||||
|
#else
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
string a_config;
|
|
||||||
int sleepsecs = 60;
|
|
||||||
vector<string> selpatterns;
|
|
||||||
|
|
||||||
// The reexec struct is used by the daemon to shed memory after
|
// The reexec struct is used by the daemon to shed memory after
|
||||||
// the initial indexing pass and to restart when the configuration
|
// the initial indexing pass and to restart when the configuration
|
||||||
// changes
|
// changes
|
||||||
@ -582,9 +599,6 @@ int main(int argc, char **argv)
|
|||||||
o_reexec->init(argc, argv);
|
o_reexec->init(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
thisprog = path_absolute(argv[0]);
|
|
||||||
argc--; argv++;
|
|
||||||
|
|
||||||
vector<string> args = argstovector(argc, argv);
|
vector<string> args = argstovector(argc, argv);
|
||||||
|
|
||||||
// Passing args through a temp file: this is used on Windows to
|
// Passing args through a temp file: this is used on Windows to
|
||||||
@ -593,6 +607,9 @@ int main(int argc, char **argv)
|
|||||||
args = fileToArgs(args[0]);
|
args = fileToArgs(args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> selpatterns;
|
||||||
|
int sleepsecs{60};
|
||||||
|
string a_config;
|
||||||
unsigned int aremain = args.size();
|
unsigned int aremain = args.size();
|
||||||
unsigned int argidx = 0;
|
unsigned int argidx = 0;
|
||||||
for (; argidx < args.size(); argidx++) {
|
for (; argidx < args.size(); argidx++) {
|
||||||
@ -703,18 +720,13 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
string rundir;
|
string rundir;
|
||||||
config->getConfParam("idxrundir", rundir);
|
config->getConfParam("idxrundir", rundir);
|
||||||
if (!rundir.compare("tmp")) {
|
if (!rundir.empty()) {
|
||||||
LOGINFO("recollindex: changing current directory to [" <<
|
if (!rundir.compare("tmp")) {
|
||||||
tmplocation() << "]\n");
|
rundir = tmplocation();
|
||||||
if (chdir(tmplocation().c_str()) < 0) {
|
|
||||||
LOGERR("chdir(" << tmplocation() << ") failed, errno " << errno <<
|
|
||||||
"\n");
|
|
||||||
}
|
}
|
||||||
} else if (!rundir.empty()) {
|
LOGINFO("recollindex: changing current directory to [" <<rundir<<"]\n");
|
||||||
LOGINFO("recollindex: changing current directory to [" << rundir <<
|
if (!path_chdir(rundir)) {
|
||||||
"]\n");
|
LOGSYSERR("main", "chdir", rundir);
|
||||||
if (chdir(rundir.c_str()) < 0) {
|
|
||||||
LOGERR("chdir(" << rundir << ") failed, errno " << errno << "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user