From 516863b5d6f43b4ba418d0f6a665d3d7b2f8573f Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 20 Jan 2012 17:48:55 +0100 Subject: [PATCH] GUI: perform up to date check before previewing a subdoc. This is for example to avoid showing the wrong message if a mail folder has been compacted --- src/index/fsindexer.cpp | 2 +- src/index/fsindexer.h | 5 ++++- src/internfile/internfile.cpp | 36 +++++++++++++++++++++++++++++++++++ src/internfile/internfile.h | 5 +++++ src/qtgui/rclmain_w.cpp | 23 ++++++++++++++++++++++ src/rcldb/rcldb.cpp | 26 +++++++++++++------------ 6 files changed, 83 insertions(+), 14 deletions(-) diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index eb6dd0c8..0c1118eb 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -282,7 +282,7 @@ void FsIndexer::setlocalfields(Rcl::Doc& doc) } } -static void makesig(const struct stat *stp, string& out) +void FsIndexer::makesig(const struct stat *stp, string& out) { char cbuf[100]; sprintf(cbuf, OFFTPC "%ld", stp->st_size, (long)stp->RCL_STTIME); diff --git a/src/index/fsindexer.h b/src/index/fsindexer.h index 91e18f9c..7a254ce4 100644 --- a/src/index/fsindexer.h +++ b/src/index/fsindexer.h @@ -24,10 +24,10 @@ using std::list; #include "indexer.h" #include "fstreewalk.h" -#include "rcldb.h" class DbIxStatusUpdater; class FIMissingStore; +struct stat; /** Index selected parts of the file system @@ -69,6 +69,9 @@ class FsIndexer : public FsTreeWalkerCB { FsTreeWalker::Status processone(const string &fn, const struct stat *, FsTreeWalker::CbFlag); + /** Make signature for file up to date checks */ + static void makesig(const struct stat *stp, string& out); + private: FsTreeWalker m_walker; RclConfig *m_config; diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index 3183fff4..3b0b60dc 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -441,6 +441,42 @@ FileInterner::FileInterner(const Rcl::Doc& idoc, RclConfig *cnf, } } +#include "fsindexer.h" +bool FileInterner::makesig(const Rcl::Doc& idoc, string& sig) +{ + if (idoc.url.empty()) { + LOGERR(("FileInterner::makesig:: no url!\n")); + return false; + } + string backend; + idoc.getmeta(Rcl::Doc::keybcknd, &backend); + + if (backend.empty() || !backend.compare("FS")) { + if (idoc.url.find(cstr_fileu) != 0) { + LOGERR(("FileInterner: FS backend and non fs url: [%s]\n", + idoc.url.c_str())); + return false; + } + string fn = idoc.url.substr(7, string::npos); + struct stat st; + if (stat(fn.c_str(), &st) < 0) { + LOGERR(("FileInterner:: cannot access document file: [%s]\n", + fn.c_str())); + return false; + } + FsIndexer::makesig(&st, sig); + return true; + } else if (!backend.compare("BGL")) { + // Bgl sigs are empty + sig.clear(); + return true; + } else { + LOGERR(("FileInterner:: unknown backend: [%s]\n", backend.c_str())); + return false; + } + return false; +} + FileInterner::~FileInterner() { tmpcleanup(); diff --git a/src/internfile/internfile.h b/src/internfile/internfile.h index 13e07046..1eabb931 100644 --- a/src/internfile/internfile.h +++ b/src/internfile/internfile.h @@ -121,6 +121,11 @@ class FileInterner { FileInterner(const Rcl::Doc& idoc, RclConfig *cnf, TempDir &td, int flags); + /** + * Build sig for doc coming from rcldb. This is here because we know how + * to query the right backend */ + static bool makesig(const Rcl::Doc& idoc, string& sig); + ~FileInterner(); void setMissingStore(FIMissingStore *st) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 5bbb7e80..97fca98e 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -945,6 +945,29 @@ void RclMain::previewClosed(Preview *w) void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod) { LOGDEB(("startPreview(%d, doc, %d)\n", docnum, mod)); + + // Document up to date check. We do this only if ipath is not + // empty as this does not appear to be a serious issue for single + // docs (the main actual problem is displaying the wrong message + // from a compacted mail folder) + if (!doc.ipath.empty()) { + string udi, sig; + doc.getmeta(Rcl::Doc::keyudi, &udi); + FileInterner::makesig(doc, sig); + if (rcldb && !udi.empty()) { + if (rcldb->needUpdate(udi, sig)) { + fprintf(stderr, "AFTER UPDATE CHECK-1\n"); + QMessageBox::warning(0, tr("Warning"), + tr("Index not up to date for this file. " + "Refusing to risk showing the wrong " + "data. Please run indexing"), + QMessageBox::Ok, + QMessageBox::NoButton); + return; + } + } + } + if (mod & Qt::ShiftModifier) { // User wants new preview window curPreview = 0; diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index dddde880..8c2a656b 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -1370,19 +1370,21 @@ bool Db::needUpdate(const string &udi, const string& sig) // Up to date. // Set the uptodate flag for doc / pseudo doc - updated[*docid] = true; + if (m_mode != DbRO) { + updated[*docid] = true; - // Set the existence flag for all the subdocs (if any) - vector docids; - if (!m_ndb->subDocs(udi, docids)) { - LOGERR(("Rcl::Db::needUpdate: can't get subdocs list\n")); - return true; - } - for (vector::iterator it = docids.begin(); - it != docids.end(); it++) { - if (*it < updated.size()) { - LOGDEB2(("Db::needUpdate: set flag for docid %d\n", *it)); - updated[*it] = true; + // Set the existence flag for all the subdocs (if any) + vector docids; + if (!m_ndb->subDocs(udi, docids)) { + LOGERR(("Rcl::Db::needUpdate: can't get subdocs list\n")); + return true; + } + for (vector::iterator it = docids.begin(); + it != docids.end(); it++) { + if (*it < updated.size()) { + LOGDEB2(("Db::needUpdate: set flag for docid %d\n", *it)); + updated[*it] = true; + } } } return false;