Ensure that the tmp environment (e.g. RECOLL_TMPDIR) is used on Windows.

This commit is contained in:
Jean-Francois Dockes 2020-05-31 16:27:37 +01:00
parent f3858a7e3a
commit c84b61a6d8
2 changed files with 30 additions and 19 deletions

View File

@ -233,13 +233,20 @@ bool RclMain::maybeArgsToFile(vector<string>& args)
TempFile temp(""); TempFile temp("");
m_idxargstmp = rememberTempFile(temp); m_idxargstmp = rememberTempFile(temp);
} }
LOGDEB0("RclMain::maybeArgsToFile: temp file name [" <<
m_idxargstmp->filename() << "]\n");
bool hasrclindex = (args[0] == "recollindex"); bool hasrclindex = (args[0] == "recollindex");
if (hasrclindex) { if (hasrclindex) {
args.erase(args.begin()); args.erase(args.begin());
} }
string s; string s;
stringsToString(args, s); stringsToString(args, s);
fstream fout(m_idxargstmp->filename(), ios::out|ios::trunc); fstream fout;
if (!path_open(m_idxargstmp->filename(), ios::out|ios::trunc, fout)) {
QMessageBox::warning(
0, "Recoll", tr("Could not start recollindex (temp file error)"));
return false;
}
fout << s; fout << s;
fout.close(); fout.close();
if (hasrclindex) { if (hasrclindex) {
@ -258,7 +265,9 @@ bool RclMain::checkIdxPaths()
{ {
string badpaths; string badpaths;
vector<string> args{"recollindex", "-c", theconfig->getConfDir(), "-E"}; vector<string> args{"recollindex", "-c", theconfig->getConfDir(), "-E"};
maybeArgsToFile(args); if (!maybeArgsToFile(args)) {
return false;
}
ExecCmd::backtick(args, badpaths); ExecCmd::backtick(args, badpaths);
if (!badpaths.empty()) { if (!badpaths.empty()) {
int rep = QMessageBox::warning( int rep = QMessageBox::warning(
@ -328,7 +337,9 @@ void RclMain::toggleIndexing()
args.push_back(m_idxreasontmp->filename()); args.push_back(m_idxreasontmp->filename());
} }
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
maybeArgsToFile(args); if (!maybeArgsToFile(args)) {
return;
}
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
} }
break; break;
@ -434,7 +445,9 @@ void RclMain::rebuildIndex()
args.push_back(m_idxreasontmp->filename()); args.push_back(m_idxreasontmp->filename());
} }
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
maybeArgsToFile(args); if (!maybeArgsToFile(args)) {
return;
}
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
} }
} }
@ -561,7 +574,9 @@ void RclMain::specialIndex()
args.push_back(top); args.push_back(top);
} }
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
maybeArgsToFile(args); if (!maybeArgsToFile(args)) {
return;
}
LOGINFO("specialIndex: exec: " << execToString("recollindex", args) <<endl); LOGINFO("specialIndex: exec: " << execToString("recollindex", args) <<endl);
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
} }
@ -584,7 +599,9 @@ void RclMain::updateIdxForDocs(vector<Rcl::Doc>& docs)
} }
args.insert(args.end(), paths.begin(), paths.end()); args.insert(args.end(), paths.begin(), paths.end());
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
maybeArgsToFile(args); if (!maybeArgsToFile(args)) {
return;
}
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
// Call periodic100 to update the menu entries states // Call periodic100 to update the menu entries states
periodic100(); periodic100();

View File

@ -129,7 +129,8 @@ static const string& path_wingetrcltmpdir()
static bool path_gettempfilename(string& filename, string&) static bool path_gettempfilename(string& filename, string&)
{ {
string tdir = path_wingetrcltmpdir(); string tdir = tmplocation();
LOGDEB0("path_gettempfilename: tdir: [" << tdir << "]\n");
wchar_t dbuf[MAX_PATH + 1]; wchar_t dbuf[MAX_PATH + 1];
utf8towchar(tdir, dbuf, MAX_PATH); utf8towchar(tdir, dbuf, MAX_PATH);
@ -145,6 +146,7 @@ static bool path_gettempfilename(string& filename, string&)
LOGDEB1("path_wingettempfilename: DeleteFile " << filename << " Ok\n"); LOGDEB1("path_wingettempfilename: DeleteFile " << filename << " Ok\n");
} }
path_slashize(filename); path_slashize(filename);
LOGDEB1("path_gettempfilename: filename: [" << filename << "]\n");
return true; return true;
} }
@ -312,9 +314,7 @@ const string& tmplocation()
} }
if (tmpdir == 0) { if (tmpdir == 0) {
#ifdef _WIN32 #ifdef _WIN32
wchar_t bufw[MAX_PATH + 1]; stmpdir = path_wingetrcltmpdir();
GetTempPathW(MAX_PATH + 1, bufw);
wchartoutf8(bufw, stmpdir);
#else #else
stmpdir = "/tmp"; stmpdir = "/tmp";
#endif #endif
@ -444,24 +444,18 @@ TempFile::Internal::Internal(const string& suffix)
return; return;
} }
m_filename += suffix; m_filename += suffix;
LOGDEB1("TempFile: filename: " << m_filename << endl); std::fstream fout;
int fd1 = open(m_filename.c_str(), O_CREAT | O_EXCL, 0600); if (!path_open(m_filename, ios::out|ios::trunc, fout)) {
if (fd1 < 0) {
m_reason = string("Open/create error. errno : ") + m_reason = string("Open/create error. errno : ") +
lltodecstr(errno) + " file name: " + m_filename; lltodecstr(errno) + " file name: " + m_filename;
LOGSYSERR("Tempfile::Internal::Internal", "open/create", m_filename);
m_filename.erase(); m_filename.erase();
} else {
close(fd1);
} }
} }
const std::string& TempFile::rcltmpdir() const std::string& TempFile::rcltmpdir()
{ {
#ifdef _WIN32
return path_wingetrcltmpdir();
#else
return tmplocation(); return tmplocation();
#endif
} }
#ifdef _WIN32 #ifdef _WIN32