From 3f7d270691e2b48f336bfacfcb9ee4554902bbbf Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 24 Jun 2019 17:37:37 +0200 Subject: [PATCH] GUI preview: improve operation when the index data is not up to date. Avoid erasing all the file index data in case the subsequent update fails (e.g. the file is locked). Improve the messages. Check for previous indexing error, and modify the message. --- .gitignore | 3 ++- src/qtgui/rclm_idx.cpp | 26 +++++++++++--------- src/qtgui/rclm_preview.cpp | 24 +++++++++++++------ src/rcldb/rcldb.cpp | 49 +++++++++++++++++++++++++++++++++++++- src/rcldb/rcldb.h | 6 +++++ 5 files changed, 88 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 62a4b003..914728eb 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,9 @@ \#* libtool ptrans -src/python/pychm/setup.py src/Makefile src/Makefile.in +src/TAGS src/aclocal.m4 src/autom4te.cache src/common/autoconfig.h @@ -50,6 +50,7 @@ src/m4/ltsugar.m4 src/m4/ltversion.m4 src/m4/lt~obsolete.m4 src/missing +src/python/pychm/setup.py src/python/recoll/Makefile src/python/recoll/build src/python/recoll/recoll/__init__.pyc diff --git a/src/qtgui/rclm_idx.cpp b/src/qtgui/rclm_idx.cpp index 121d44b4..b0c48324 100644 --- a/src/qtgui/rclm_idx.cpp +++ b/src/qtgui/rclm_idx.cpp @@ -87,6 +87,13 @@ void RclMain::updateIdxStatus() void RclMain::periodic100() { LOGDEB2("Periodic100\n" ); + if (!m_idxreasontmp || !m_idxreasontmp->ok()) { + // We just store the pointer and let the tempfile cleaner deal + // with delete on exiting + TempFile temp(".txt"); + m_idxreasontmp = rememberTempFile(temp); + } + if (m_idxproc) { // An indexing process was launched. If its' done, see status. int status; @@ -237,13 +244,6 @@ bool RclMain::checkIdxPaths() // re-enabled by the indexing status check void RclMain::toggleIndexing() { - if (!m_idxreasontmp || !m_idxreasontmp->ok()) { - // We just store the pointer and let the tempfile cleaner deal - // with delete on exiting - TempFile temp(".txt"); - m_idxreasontmp = rememberTempFile(temp); - } - switch (m_indexerState) { case IXST_RUNNINGMINE: if (m_idxproc) { @@ -537,7 +537,7 @@ void RclMain::updateIdxForDocs(vector& docs) vector paths; if (Rcl::docsToPaths(docs, paths)) { - vector args{"-c", theconfig->getConfDir(), "-e", "-i"}; + vector args{"-c", theconfig->getConfDir(), "-i",}; if (m_idxreasontmp && m_idxreasontmp->ok()) { args.push_back("-R"); args.push_back(m_idxreasontmp->filename()); @@ -545,8 +545,12 @@ void RclMain::updateIdxForDocs(vector& docs) args.insert(args.end(), paths.begin(), paths.end()); m_idxproc = new ExecCmd; m_idxproc->startExec("recollindex", args, false, false); - fileToggleIndexingAction->setText(tr("Stop &Indexing")); + // Call periodic100 to update the menu entries states + periodic100(); + } else { + QMessageBox::warning(0, tr("Warning"), + tr("Can't update index: internal error"), + QMessageBox::Ok, QMessageBox::NoButton); + return; } - fileToggleIndexingAction->setEnabled(false); - actionSpecial_Indexing->setEnabled(false); } diff --git a/src/qtgui/rclm_preview.cpp b/src/qtgui/rclm_preview.cpp index 02586b7d..759ec767 100644 --- a/src/qtgui/rclm_preview.cpp +++ b/src/qtgui/rclm_preview.cpp @@ -79,17 +79,27 @@ bool RclMain::containerUpToDate(Rcl::Doc& doc) return true; } + // Top level (container) document, for checking for indexing error + string ctsig = "+"; + Rcl::Doc ctdoc; + if (rcldb->getContainerDoc(doc, ctdoc)) { + ctdoc.getmeta(Rcl::Doc::keysig, &ctsig); + } + // We can only run indexing on the main index (dbidx 0) bool ismainidx = rcldb->fromMainIndex(doc); // Indexer already running? bool ixnotact = (m_indexerState == IXST_NOTRUNNING); - QString msg = tr("Index not up to date for this file. " - "Refusing to risk showing the wrong entry. "); + QString msg = tr("Index not up to date for this file.
"); + if (ctsig.back() == '+') { + msg += tr("Also, it seems that the last index update for the file " + "failed.
"); + } if (ixnotact && ismainidx) { - msg += tr("Click Ok to update the " - "index for this file, then you will need to " - "re-run the query when indexing is done. "); + msg += tr("Click Ok to try to update the " + "index for this file. You will need to " + "run the query again when indexing is done.
"); } else if (ismainidx) { msg += tr("The indexer is running so things should " "improve when it's done. "); @@ -98,9 +108,9 @@ bool RclMain::containerUpToDate(Rcl::Doc& doc) msg += tr("The document belongs to an external index " "which I can't update. "); } - msg += tr("Click Cancel to return to the list.
" + msg += tr("Click Cancel to return to the list.
" "Click Ignore to show the preview anyway (and remember for " - "this session)."); + "this session). There is a risk of showing the wrong entry.
"); QMessageBox::StandardButtons bts = QMessageBox::Ignore | QMessageBox::Cancel; diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index d5df5c4c..0584c485 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -2584,6 +2584,53 @@ bool Db::getSubDocs(const Doc &idoc, vector& subdocs) return false; } +bool Db::getContainerDoc(const Doc &idoc, Doc& ctdoc) +{ + if (m_ndb == 0) + return false; + + string inudi; + if (!idoc.getmeta(Doc::keyudi, &inudi) || inudi.empty()) { + LOGERR("Db::getContainerDoc: no input udi or empty\n"); + return false; + } + + string rootudi; + string ipath = idoc.ipath; + LOGDEB0("Db::getContainerDoc: idxi " << idoc.idxi << " inudi [" << inudi << + "] ipath [" << ipath << "]\n"); + if (ipath.empty()) { + // File-level doc ?? + ctdoc = idoc; + return true; + } + // See if we have a parent term + Xapian::Document xdoc; + if (!m_ndb->getDoc(inudi, idoc.idxi, xdoc)) { + LOGERR("Db::getContainerDoc: can't get Xapian document\n"); + return false; + } + Xapian::TermIterator xit; + XAPTRY(xit = xdoc.termlist_begin(); + xit.skip_to(wrap_prefix(parent_prefix)), + m_ndb->xrdb, m_reason); + if (!m_reason.empty()) { + LOGERR("Db::getContainerDoc: xapian error: " << m_reason << "\n"); + return false; + } + if (xit == xdoc.termlist_end()) { + LOGERR("Db::getContainerDoc: parent term not found\n"); + return false; + } + rootudi = strip_prefix(*xit); + + if (!getDoc(rootudi, idoc.idxi, ctdoc)) { + LOGERR("Db::getContainerDoc: can't get container document\n"); + return false; + } + return true; +} + // Walk an UDI section (all UDIs beginning with input prefix), and // mark all docs and subdocs as existing. Caller beware: Makes sense // or not depending on the UDI structure for the data store. In practise, @@ -2614,7 +2661,7 @@ bool Db::udiTreeMarkExisting(const string& udi) return false; } i_setExistingFlags(udi, *docid); - LOGDEB("Db::udiTreeWalk: uniterm: " << term << endl); + LOGDEB0("Db::udiTreeWalk: uniterm: " << term << endl); return true; }, wrapd); return ret; diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index a234c319..10d446e0 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -455,6 +455,12 @@ public: */ bool getSubDocs(const Doc& idoc, vector& subdocs); + /** Get container (top level file) document. + * + * If the input is not a subdocument, this returns a copy of the input. + */ + bool getContainerDoc(const Doc &idoc, Doc& ctdoc); + /** Get duplicates (md5) of document */ bool docDups(const Doc& idoc, std::vector& odocs);