make indexation more easily cancellable
This commit is contained in:
parent
e9d722e25c
commit
962f6f1012
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.29 2006-04-04 12:37:51 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.30 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -200,8 +200,11 @@ FsTreeWalker::Status
|
|||||||
DbIndexer::processone(const std::string &fn, const struct stat *stp,
|
DbIndexer::processone(const std::string &fn, const struct stat *stp,
|
||||||
FsTreeWalker::CbFlag flg)
|
FsTreeWalker::CbFlag flg)
|
||||||
{
|
{
|
||||||
if (m_updfunc)
|
if (m_updfunc) {
|
||||||
m_updfunc->update(fn);
|
if (!m_updfunc->update(fn)) {
|
||||||
|
return FsTreeWalker::FtwStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
// If we're changing directories, possibly adjust parameters (set
|
// If we're changing directories, possibly adjust parameters (set
|
||||||
// the current directory in configuration object)
|
// the current directory in configuration object)
|
||||||
if (flg == FsTreeWalker::FtwDirEnter ||
|
if (flg == FsTreeWalker::FtwDirEnter ||
|
||||||
@ -222,6 +225,7 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
|
|||||||
|
|
||||||
FileInterner interner(fn, m_config, m_tmpdir);
|
FileInterner interner(fn, m_config, m_tmpdir);
|
||||||
FileInterner::Status fis = FileInterner::FIAgain;
|
FileInterner::Status fis = FileInterner::FIAgain;
|
||||||
|
int i = 0;
|
||||||
while (fis == FileInterner::FIAgain) {
|
while (fis == FileInterner::FIAgain) {
|
||||||
Rcl::Doc doc;
|
Rcl::Doc doc;
|
||||||
string ipath;
|
string ipath;
|
||||||
@ -229,6 +233,12 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
|
|||||||
if (fis == FileInterner::FIError)
|
if (fis == FileInterner::FIError)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (m_updfunc) {
|
||||||
|
if ((++i % 100) == 0 && !m_updfunc->update(fn+"|"+ipath)) {
|
||||||
|
return FsTreeWalker::FtwStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the date if this was not done in the document handler
|
// Set the date if this was not done in the document handler
|
||||||
if (doc.fmtime.empty()) {
|
if (doc.fmtime.empty()) {
|
||||||
char ascdate[20];
|
char ascdate[20];
|
||||||
@ -292,13 +302,13 @@ bool ConfIndexer::index(bool resetbefore)
|
|||||||
if (lstat(doctopdir.c_str(), &st) < 0) {
|
if (lstat(doctopdir.c_str(), &st) < 0) {
|
||||||
LOGERR(("ConfIndexer::index: cant stat %s\n",
|
LOGERR(("ConfIndexer::index: cant stat %s\n",
|
||||||
doctopdir.c_str()));
|
doctopdir.c_str()));
|
||||||
m_reason = string("Stat error for: ") + doctopdir;
|
m_reason = "Stat error for: " + doctopdir;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (S_ISLNK(st.st_mode)) {
|
if (S_ISLNK(st.st_mode)) {
|
||||||
LOGERR(("ConfIndexer::index: no symlinks allowed in topdirs: %s\n",
|
LOGERR(("ConfIndexer::index: no symlinks allowed in topdirs: %s\n",
|
||||||
doctopdir.c_str()));
|
doctopdir.c_str()));
|
||||||
m_reason = doctopdir + "is a symbolic link";
|
m_reason = doctopdir + " is a symbolic link";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -306,7 +316,7 @@ bool ConfIndexer::index(bool resetbefore)
|
|||||||
if (!m_config->getConfParam("dbdir", dbdir)) {
|
if (!m_config->getConfParam("dbdir", dbdir)) {
|
||||||
LOGERR(("ConfIndexer::index: no database directory in "
|
LOGERR(("ConfIndexer::index: no database directory in "
|
||||||
"configuration for %s\n", doctopdir.c_str()));
|
"configuration for %s\n", doctopdir.c_str()));
|
||||||
m_reason = string("No database directory set for ") + doctopdir;
|
m_reason = "No database directory set for " + doctopdir;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dbdir = path_tildexpand(dbdir);
|
dbdir = path_tildexpand(dbdir);
|
||||||
@ -333,7 +343,7 @@ bool ConfIndexer::index(bool resetbefore)
|
|||||||
m_dbindexer = new DbIndexer(m_config, dbit->first, m_updfunc);
|
m_dbindexer = new DbIndexer(m_config, dbit->first, m_updfunc);
|
||||||
if (!m_dbindexer->indexDb(resetbefore, &dbit->second)) {
|
if (!m_dbindexer->indexDb(resetbefore, &dbit->second)) {
|
||||||
deleteZ(m_dbindexer);
|
deleteZ(m_dbindexer);
|
||||||
m_reason = string("Failed indexing in ") + dbit->first;
|
m_reason = "Failed indexing in " + dbit->first;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
deleteZ(m_dbindexer);
|
deleteZ(m_dbindexer);
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _INDEXER_H_INCLUDED_
|
#ifndef _INDEXER_H_INCLUDED_
|
||||||
#define _INDEXER_H_INCLUDED_
|
#define _INDEXER_H_INCLUDED_
|
||||||
/* @(#$Id: indexer.h,v 1.13 2006-04-04 12:37:51 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: indexer.h,v 1.14 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -28,11 +28,12 @@
|
|||||||
/* Forward decl for lower level indexing object */
|
/* Forward decl for lower level indexing object */
|
||||||
class DbIndexer;
|
class DbIndexer;
|
||||||
|
|
||||||
/* Callback to say what we're doing */
|
/* Callback to say what we're doing. If the update func returns false, we
|
||||||
|
* stop */
|
||||||
class DbIxStatusUpdater {
|
class DbIxStatusUpdater {
|
||||||
public:
|
public:
|
||||||
virtual ~DbIxStatusUpdater(){}
|
virtual ~DbIxStatusUpdater(){}
|
||||||
virtual void update(const std::string &) = 0;
|
virtual bool update(const std::string &) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.16 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.17 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -83,11 +83,27 @@ static void cleanup()
|
|||||||
dbindexer = 0;
|
dbindexer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stopindexing;
|
||||||
|
string currentfile;
|
||||||
|
// Mainly used to request indexing stop, we currently do not use the
|
||||||
|
// current file name
|
||||||
|
class MyUpdater : public DbIxStatusUpdater {
|
||||||
|
public:
|
||||||
|
virtual bool update(const string &fn) {
|
||||||
|
currentfile = fn;
|
||||||
|
if (stopindexing) {
|
||||||
|
stopindexing = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MyUpdater updater;
|
||||||
|
|
||||||
static void sigcleanup(int sig)
|
static void sigcleanup(int sig)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "sigcleanup\n");
|
fprintf(stderr, "sigcleanup\n");
|
||||||
cleanup();
|
stopindexing = 1;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *thisprog;
|
static const char *thisprog;
|
||||||
@ -173,7 +189,7 @@ int main(int argc, const char **argv)
|
|||||||
string lang = *argv++; argc--;
|
string lang = *argv++; argc--;
|
||||||
exit(!createstemdb(config, lang));
|
exit(!createstemdb(config, lang));
|
||||||
} else {
|
} else {
|
||||||
confindexer = new ConfIndexer(config);
|
confindexer = new ConfIndexer(config, &updater);
|
||||||
bool rezero(op_flags & OPT_z);
|
bool rezero(op_flags & OPT_z);
|
||||||
exit(!confindexer->index(rezero));
|
exit(!confindexer->index(rezero));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,20 +30,26 @@ static QMutex curfile_mutex;
|
|||||||
class IdxThread : public QThread , public DbIxStatusUpdater {
|
class IdxThread : public QThread , public DbIxStatusUpdater {
|
||||||
virtual void run();
|
virtual void run();
|
||||||
public:
|
public:
|
||||||
virtual void update(const string &fn) {
|
virtual bool update(const string &fn) {
|
||||||
QMutexLocker locker(&curfile_mutex);
|
QMutexLocker locker(&curfile_mutex);
|
||||||
m_curfile = fn;
|
m_curfile = fn;
|
||||||
LOGDEB(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
|
LOGDEB1(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
|
||||||
|
if (stopindexing) {
|
||||||
|
stopindexing = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
ConfIndexer *indexer;
|
ConfIndexer *indexer;
|
||||||
string m_curfile;
|
string m_curfile;
|
||||||
int loglevel;
|
int loglevel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int stopindexing;
|
||||||
int startindexing;
|
int startindexing;
|
||||||
int indexingdone = 1;
|
int indexingdone = 1;
|
||||||
bool indexingstatus = false;
|
IdxThreadStatus indexingstatus = IDXTS_NULL;
|
||||||
|
string indexingReason;
|
||||||
static int stopidxthread;
|
static int stopidxthread;
|
||||||
|
|
||||||
void IdxThread::run()
|
void IdxThread::run()
|
||||||
@ -55,10 +61,16 @@ void IdxThread::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (startindexing) {
|
if (startindexing) {
|
||||||
indexingdone = indexingstatus = 0;
|
|
||||||
fprintf(stderr, "Index thread :start index\n");
|
|
||||||
indexingstatus = indexer->index();
|
|
||||||
startindexing = 0;
|
startindexing = 0;
|
||||||
|
indexingdone = 0;
|
||||||
|
indexingstatus = IDXTS_NULL;
|
||||||
|
if (indexer->index()) {
|
||||||
|
indexingstatus = IDXTS_OK;
|
||||||
|
indexingReason = "";
|
||||||
|
} else {
|
||||||
|
indexingstatus = IDXTS_ERROR;
|
||||||
|
indexingReason = "Indexation failed: " + indexer->getReason();
|
||||||
|
}
|
||||||
indexingdone = 1;
|
indexingdone = 1;
|
||||||
}
|
}
|
||||||
msleep(100);
|
msleep(100);
|
||||||
@ -80,6 +92,7 @@ void start_idxthread(const RclConfig& cnf)
|
|||||||
|
|
||||||
void stop_idxthread()
|
void stop_idxthread()
|
||||||
{
|
{
|
||||||
|
stopindexing = 1;
|
||||||
stopidxthread = 1;
|
stopidxthread = 1;
|
||||||
idxthread.wait();
|
idxthread.wait();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _IDXTHREAD_H_INCLUDED_
|
#ifndef _IDXTHREAD_H_INCLUDED_
|
||||||
#define _IDXTHREAD_H_INCLUDED_
|
#define _IDXTHREAD_H_INCLUDED_
|
||||||
/* @(#$Id: idxthread.h,v 1.4 2006-03-22 16:24:41 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: idxthread.h,v 1.5 2006-04-04 13:49:55 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class RclConfig;
|
class RclConfig;
|
||||||
@ -27,8 +27,11 @@ extern void start_idxthread(const RclConfig& cnf);
|
|||||||
extern void stop_idxthread();
|
extern void stop_idxthread();
|
||||||
extern std::string idxthread_currentfile();
|
extern std::string idxthread_currentfile();
|
||||||
|
|
||||||
|
extern int stopindexing;
|
||||||
extern int startindexing;
|
extern int startindexing;
|
||||||
extern int indexingdone;
|
extern int indexingdone;
|
||||||
extern bool indexingstatus;
|
enum IdxThreadStatus {IDXTS_NULL = 0, IDXTS_OK = 1, IDXTS_ERROR = 2};
|
||||||
|
extern IdxThreadStatus indexingstatus;
|
||||||
|
extern string indexingReason;
|
||||||
|
|
||||||
#endif /* _IDXTHREAD_H_INCLUDED_ */
|
#endif /* _IDXTHREAD_H_INCLUDED_ */
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.18 2006-04-04 07:55:29 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.19 2006-04-04 13:49:55 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -211,9 +211,14 @@ void RclMain::periodic100()
|
|||||||
{
|
{
|
||||||
static int toggle = 0;
|
static int toggle = 0;
|
||||||
// Check if indexing thread done
|
// Check if indexing thread done
|
||||||
if (indexingstatus) {
|
if (indexingstatus != IDXTS_NULL) {
|
||||||
statusBar()->message("");
|
statusBar()->message("");
|
||||||
indexingstatus = false;
|
if (indexingstatus != IDXTS_OK) {
|
||||||
|
indexingstatus = IDXTS_NULL;
|
||||||
|
QMessageBox::warning(0, "Recoll",
|
||||||
|
QString::fromAscii(indexingReason.c_str()));
|
||||||
|
}
|
||||||
|
indexingstatus = IDXTS_NULL;
|
||||||
// Make sure we reopen the db to get the results.
|
// Make sure we reopen the db to get the results.
|
||||||
LOGINFO(("Indexing done: closing query database\n"));
|
LOGINFO(("Indexing done: closing query database\n"));
|
||||||
rcldb->close();
|
rcldb->close();
|
||||||
@ -240,7 +245,7 @@ void RclMain::periodic100()
|
|||||||
|
|
||||||
void RclMain::fileStart_IndexingAction_activated()
|
void RclMain::fileStart_IndexingAction_activated()
|
||||||
{
|
{
|
||||||
if (indexingdone == 1)
|
if (indexingdone)
|
||||||
startindexing = 1;
|
startindexing = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user