Merge 1.23 Windows changes intended to improve the index rebuild failures caused by open files

This commit is contained in:
Jean-Francois Dockes 2018-01-25 15:34:27 +01:00
commit cecd1b4ba7
9 changed files with 62 additions and 15 deletions

View File

@ -492,7 +492,7 @@ static inline bool isdigit(int what, unsigned int flgs)
#define STATS_INC_WORDCHARS #define STATS_INC_WORDCHARS
#endif #endif
vector<CharFlags> splitFlags = { vector<CharFlags> splitFlags{
{TextSplit::TXTS_NOSPANS, "nospans"}, {TextSplit::TXTS_NOSPANS, "nospans"},
{TextSplit::TXTS_ONLYSPANS, "onlyspans"}, {TextSplit::TXTS_ONLYSPANS, "onlyspans"},
{TextSplit::TXTS_KEEPWILD, "keepwild"} {TextSplit::TXTS_KEEPWILD, "keepwild"}

View File

@ -79,8 +79,6 @@ bool EXEDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
// Lookup bckid in the config and create an appropriate fetcher. // Lookup bckid in the config and create an appropriate fetcher.
EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const string& bckid) EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const string& bckid)
{ {
EXEDocFetcher *fetcher = 0;
// The config we only read once, not gonna change. // The config we only read once, not gonna change.
static ConfSimple *bconf; static ConfSimple *bconf;
if (!bconf) { if (!bconf) {

View File

@ -29,6 +29,7 @@
#include "rclmain_w.h" #include "rclmain_w.h"
#include "specialindex.h" #include "specialindex.h"
#include "readfile.h" #include "readfile.h"
#include "snippets_w.h"
using namespace std; using namespace std;
@ -291,8 +292,20 @@ void RclMain::toggleIndexing()
} }
} }
static void delay(int millisecondsWait)
{
QEventLoop loop;
QTimer t;
t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
t.start(millisecondsWait);
loop.exec();
}
void RclMain::rebuildIndex() void RclMain::rebuildIndex()
{ {
if (m_indexerState == IXST_UNKNOWN) {
delay(1500);
}
switch (m_indexerState) { switch (m_indexerState) {
case IXST_UNKNOWN: case IXST_UNKNOWN:
case IXST_RUNNINGMINE: case IXST_RUNNINGMINE:
@ -313,12 +326,24 @@ void RclMain::rebuildIndex()
QMessageBox::NoButton); QMessageBox::NoButton);
if (rep == QMessageBox::Ok) { if (rep == QMessageBox::Ok) {
#ifdef _WIN32 #ifdef _WIN32
// Under windows, it's necessary to close the db here, // Under windows, it is necessary to close the db here,
// else Xapian won't be able to do what it wants with the // else Xapian won't be able to do what it wants with the
// (open) files. Of course if there are several GUI // (open) files. Of course if there are several GUI
// instances, this won't work... // instances, this won't work... Also it's quite difficult
if (rcldb) // to make sure that there are no more references to the
// db because, for example of the Enquire objects inside
// Query inside Docsource etc.
//
// !! At this moment, this does not work if a preview has
// !! been opened. Could not find the reason (mysterious
// !! Xapian::Database reference somewhere?). The indexing
// !! fails, leaving a partial index directory. Then need
// !! to restart the GUI to succeed in reindexing.
if (rcldb) {
resetSearch();
deleteZ(m_snippets);
rcldb->close(); rcldb->close();
}
#endif // _WIN32 #endif // _WIN32
// Could also mean that no helpers are missing, but then we // Could also mean that no helpers are missing, but then we
// won't try to show a message anyway (which is what // won't try to show a message anyway (which is what

View File

@ -451,13 +451,16 @@ void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
void RclMain::showSnippets(Rcl::Doc doc) void RclMain::showSnippets(Rcl::Doc doc)
{ {
SnippetsW *sp = new SnippetsW(doc, m_source); if (m_snippets) {
connect(sp, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)), deleteZ(m_snippets);
}
m_snippets = new SnippetsW(doc, m_source);
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString))); this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, sp), SIGNAL (activated()), connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()),
this, SLOT (fileExit())); this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, sp), SIGNAL (activated()), connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()),
sp, SLOT (close())); m_snippets, SLOT (close()));
sp->show(); m_snippets->show();
} }

View File

@ -531,7 +531,7 @@ void RclMain::initDbOpen()
connect(fidia.idxschedCLB, SIGNAL(clicked()), connect(fidia.idxschedCLB, SIGNAL(clicked()),
this, SLOT(execIndexSched())); this, SLOT(execIndexSched()));
connect(fidia.runidxPB, SIGNAL(clicked()), connect(fidia.runidxPB, SIGNAL(clicked()),
this, SLOT(toggleIndexing())); this, SLOT(rebuildIndex()));
fidia.exec(); fidia.exec();
// Don't open adv search or run cmd line search in this case. // Don't open adv search or run cmd line search in this case.
return; return;
@ -788,6 +788,7 @@ void RclMain::initiateQuery()
void RclMain::resetSearch() void RclMain::resetSearch()
{ {
m_source = std::shared_ptr<DocSequence>();
emit searchReset(); emit searchReset();
} }
@ -974,8 +975,7 @@ void RclMain::docExpand(Rcl::Doc doc)
void RclMain::showDocHistory() void RclMain::showDocHistory()
{ {
LOGDEB("RclMain::showDocHistory\n"); LOGDEB("RclMain::showDocHistory\n");
emit searchReset(); resetSearch();
m_source = std::shared_ptr<DocSequence>();
curPreview = 0; curPreview = 0;
string reason; string reason;

View File

@ -35,6 +35,7 @@
#include "guiutils.h" #include "guiutils.h"
#include "rclutil.h" #include "rclutil.h"
class SnippetsW;
class IdxSchedW; class IdxSchedW;
class ExecCmd; class ExecCmd;
class Preview; class Preview;
@ -202,6 +203,7 @@ protected:
private: private:
SnippetsW *m_snippets{0};
Preview *curPreview; Preview *curPreview;
AdvSearch *asearchform; AdvSearch *asearchform;
UIPrefsDialog *uiprefs; UIPrefsDialog *uiprefs;

View File

@ -407,6 +407,8 @@ void ResList::setDocSource(std::shared_ptr<DocSequence> nsource)
{ {
LOGDEB("ResList::setDocSource()\n"); LOGDEB("ResList::setDocSource()\n");
m_source = std::shared_ptr<DocSequence>(new DocSource(theconfig, nsource)); m_source = std::shared_ptr<DocSequence>(new DocSource(theconfig, nsource));
if (m_pager)
m_pager->setDocSource(m_source);
} }
// A query was executed, or the filtering/sorting parameters changed, // A query was executed, or the filtering/sorting parameters changed,

View File

@ -59,6 +59,7 @@ using namespace std;
#include "rclinit.h" #include "rclinit.h"
#include "internfile.h" #include "internfile.h"
#include "utf8fn.h" #include "utf8fn.h"
#include "wipedir.h"
#ifdef RCL_USE_ASPELL #ifdef RCL_USE_ASPELL
#include "rclaspell.h" #include "rclaspell.h"
#endif #endif
@ -255,6 +256,18 @@ void Db::Native::openWrite(const string& dir, Db::OpenMode mode)
int action = (mode == Db::DbUpd) ? Xapian::DB_CREATE_OR_OPEN : int action = (mode == Db::DbUpd) ? Xapian::DB_CREATE_OR_OPEN :
Xapian::DB_CREATE_OR_OVERWRITE; Xapian::DB_CREATE_OR_OVERWRITE;
#ifdef _WIN32
// Xapian is quite bad at erasing partial db which can
// occur because of open file deletion errors on
// Windows.
if (mode == DbTrunc) {
if (path_exists(path_cat(dir, "iamchert"))) {
wipedir(dir);
unlink(dir.c_str());
}
}
#endif
if (::access(dir.c_str(), 0) == 0) { if (::access(dir.c_str(), 0) == 0) {
// Existing index // Existing index
xwdb = Xapian::WritableDatabase(dir, action); xwdb = Xapian::WritableDatabase(dir, action);
@ -874,7 +887,9 @@ Db::~Db()
LOGDEB("Db::~Db: isopen " << m_ndb->m_isopen << " m_iswritable " << LOGDEB("Db::~Db: isopen " << m_ndb->m_isopen << " m_iswritable " <<
m_ndb->m_iswritable << "\n"); m_ndb->m_iswritable << "\n");
i_close(true); i_close(true);
#ifdef RCL_USE_ASPELL
delete m_aspell; delete m_aspell;
#endif
delete m_config; delete m_config;
} }

View File

@ -227,6 +227,8 @@ private:
/// Entries for the descriptive table /// Entries for the descriptive table
struct CharFlags { struct CharFlags {
CharFlags(int v, const char *y, const char *n=0)
: value(v), yesname(y), noname(n) {}
unsigned int value; // Flag or value unsigned int value; // Flag or value
const char *yesname;// String to print if flag set or equal const char *yesname;// String to print if flag set or equal
const char *noname; // String to print if flag not set (unused for values) const char *noname; // String to print if flag not set (unused for values)