TempFile: clean-up interface by using internal ref-counted class member. Uncomp: add interface to clear cache
This commit is contained in:
+7
-8
@@ -42,6 +42,7 @@
|
||||
#include "guiutils.h"
|
||||
#include "smallut.h"
|
||||
#include "readfile.h"
|
||||
#include "uncomp.h"
|
||||
|
||||
#include "recollq.h"
|
||||
|
||||
@@ -52,10 +53,11 @@ static vector<TempFile> o_tempfiles;
|
||||
/* Keep an array of temporary files for deletion at exit. It happens that we
|
||||
erase some of them before exiting (ie: when closing a preview tab), we don't
|
||||
reuse the array holes for now */
|
||||
void rememberTempFile(TempFile temp)
|
||||
TempFile *rememberTempFile(TempFile temp)
|
||||
{
|
||||
std::unique_lock<std::mutex> locker(thetempfileslock);
|
||||
o_tempfiles.push_back(temp);
|
||||
return &o_tempfiles.back();
|
||||
}
|
||||
|
||||
void forgetTempFile(string &fn)
|
||||
@@ -63,10 +65,9 @@ void forgetTempFile(string &fn)
|
||||
if (fn.empty())
|
||||
return;
|
||||
std::unique_lock<std::mutex> locker(thetempfileslock);
|
||||
for (vector<TempFile>::iterator it = o_tempfiles.begin();
|
||||
it != o_tempfiles.end(); it++) {
|
||||
if ((*it) && !fn.compare((*it)->filename())) {
|
||||
it->reset();
|
||||
for (auto& entry : o_tempfiles) {
|
||||
if (entry.ok() && !fn.compare(entry.filename())) {
|
||||
entry = TempFile();
|
||||
}
|
||||
}
|
||||
fn.erase();
|
||||
@@ -76,11 +77,10 @@ void deleteAllTempFiles()
|
||||
{
|
||||
std::unique_lock<std::mutex> locker(thetempfileslock);
|
||||
o_tempfiles.clear();
|
||||
Uncomp::clearcache();
|
||||
}
|
||||
|
||||
Rcl::Db *rcldb;
|
||||
|
||||
|
||||
int recollNeedsExit;
|
||||
RclMain *mainWindow;
|
||||
|
||||
@@ -151,7 +151,6 @@ static void recollCleanup()
|
||||
deleteZ(theconfig);
|
||||
|
||||
deleteAllTempFiles();
|
||||
|
||||
LOGDEB2("recollCleanup: done\n" );
|
||||
}
|
||||
|
||||
|
||||
@@ -832,15 +832,15 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
|
||||
// an ipath, create it.
|
||||
if (fn.empty() || !idoc.ipath.empty()) {
|
||||
TempFile temp = lthr.tmpimg;
|
||||
if (temp) {
|
||||
if (temp.ok()) {
|
||||
LOGDEB1("Preview: load: got temp file from internfile\n");
|
||||
} else if (!FileInterner::idocToFile(temp, string(),
|
||||
theconfig, idoc)) {
|
||||
temp.reset(); // just in case.
|
||||
temp = TempFile(); // just in case.
|
||||
}
|
||||
if (temp) {
|
||||
if (temp.ok()) {
|
||||
rememberTempFile(temp);
|
||||
fn = temp->filename();
|
||||
fn = temp.filename();
|
||||
editor->m_tmpfilename = fn;
|
||||
} else {
|
||||
editor->m_tmpfilename.erase();
|
||||
|
||||
@@ -86,7 +86,7 @@ void RclMain::periodic100()
|
||||
bool exited = m_idxproc->maybereap(&status);
|
||||
if (exited) {
|
||||
QString reasonmsg;
|
||||
if (m_idxreasontmp) {
|
||||
if (m_idxreasontmp && m_idxreasontmp->ok()) {
|
||||
string reasons;
|
||||
file_to_string(m_idxreasontmp->filename(), reasons);
|
||||
if (!reasons.empty()) {
|
||||
@@ -227,11 +227,11 @@ bool RclMain::checkIdxPaths()
|
||||
// re-enabled by the indexing status check
|
||||
void RclMain::toggleIndexing()
|
||||
{
|
||||
if (!m_idxreasontmp) {
|
||||
if (!m_idxreasontmp || !m_idxreasontmp->ok()) {
|
||||
// We just store the pointer and let the tempfile cleaner deal
|
||||
// with delete on exiting
|
||||
m_idxreasontmp = new TempFileInternal(".txt");
|
||||
rememberTempFile(TempFile(m_idxreasontmp));
|
||||
TempFile temp(".txt");
|
||||
m_idxreasontmp = rememberTempFile(temp);
|
||||
}
|
||||
|
||||
switch (m_indexerState) {
|
||||
@@ -281,7 +281,7 @@ void RclMain::toggleIndexing()
|
||||
return;
|
||||
}
|
||||
vector<string> args{"-c", theconfig->getConfDir()};
|
||||
if (m_idxreasontmp) {
|
||||
if (m_idxreasontmp && m_idxreasontmp->ok()) {
|
||||
args.push_back("-R");
|
||||
args.push_back(m_idxreasontmp->filename());
|
||||
}
|
||||
@@ -377,7 +377,7 @@ void RclMain::rebuildIndex()
|
||||
}
|
||||
|
||||
vector<string> args{"-c", theconfig->getConfDir(), "-z"};
|
||||
if (m_idxreasontmp) {
|
||||
if (m_idxreasontmp && m_idxreasontmp->ok()) {
|
||||
args.push_back("-R");
|
||||
args.push_back(m_idxreasontmp->filename());
|
||||
}
|
||||
@@ -458,7 +458,7 @@ void RclMain::specialIndex()
|
||||
return;
|
||||
|
||||
vector<string> args{"-c", theconfig->getConfDir()};
|
||||
if (m_idxreasontmp) {
|
||||
if (m_idxreasontmp && m_idxreasontmp->ok()) {
|
||||
args.push_back("-R");
|
||||
args.push_back(m_idxreasontmp->filename());
|
||||
}
|
||||
@@ -521,7 +521,7 @@ void RclMain::updateIdxForDocs(vector<Rcl::Doc>& docs)
|
||||
vector<string> paths;
|
||||
if (Rcl::docsToPaths(docs, paths)) {
|
||||
vector<string> args{"-c", theconfig->getConfDir(), "-e", "-i"};
|
||||
if (m_idxreasontmp) {
|
||||
if (m_idxreasontmp && m_idxreasontmp->ok()) {
|
||||
args.push_back("-R");
|
||||
args.push_back(m_idxreasontmp->filename());
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
||||
bool enterHistory = false;
|
||||
bool istempfile = false;
|
||||
|
||||
LOGDEB("RclMain::startNV: groksipath " << groksipath << " wantsf " <<
|
||||
LOGDEB("StartNativeViewer: groksipath " << groksipath << " wantsf " <<
|
||||
wantsfile << " wantsparentf " << wantsparentfile << "\n");
|
||||
|
||||
// If the command wants a file but this is not a file url, or
|
||||
@@ -332,7 +332,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
||||
enterHistory = true;
|
||||
istempfile = true;
|
||||
rememberTempFile(temp);
|
||||
fn = temp->filename();
|
||||
fn = temp.filename();
|
||||
url = path_pathtofileurl(fn);
|
||||
}
|
||||
|
||||
@@ -354,10 +354,10 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (temp) {
|
||||
if (temp.ok()) {
|
||||
istempfile = true;
|
||||
rememberTempFile(temp);
|
||||
fn = temp->filename();
|
||||
fn = temp.filename();
|
||||
url = path_pathtofileurl(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ private:
|
||||
vector<ExecCmd*> m_viewers;
|
||||
ExecCmd *m_idxproc{0}; // Indexing process
|
||||
bool m_idxkilled{false}; // Killed my process
|
||||
TempFileInternal *m_idxreasontmp{nullptr};
|
||||
TempFile *m_idxreasontmp{nullptr};
|
||||
map<QString, QAction*> m_stemLangToId;
|
||||
vector<string> m_catgbutvec;
|
||||
int m_catgbutvecidx{0};
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ bool getStemLangs(vector<string>& langs);
|
||||
|
||||
extern RclConfig *theconfig;
|
||||
|
||||
extern void rememberTempFile(TempFile);
|
||||
extern TempFile *rememberTempFile(TempFile);
|
||||
extern void forgetTempFile(string &fn);
|
||||
extern void deleteAllTempFiles();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user