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

This commit is contained in:
Jean-Francois Dockes 2012-01-20 17:48:55 +01:00
parent 036937e8bf
commit 516863b5d6
6 changed files with 83 additions and 14 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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();

View File

@ -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)

View File

@ -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;

View File

@ -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<Xapian::docid> docids;
if (!m_ndb->subDocs(udi, docids)) {
LOGERR(("Rcl::Db::needUpdate: can't get subdocs list\n"));
return true;
}
for (vector<Xapian::docid>::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<Xapian::docid> docids;
if (!m_ndb->subDocs(udi, docids)) {
LOGERR(("Rcl::Db::needUpdate: can't get subdocs list\n"));
return true;
}
for (vector<Xapian::docid>::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;