make indexation more easily cancellable

This commit is contained in:
dockes
2006-04-04 13:49:55 +00:00
parent e9d722e25c
commit 962f6f1012
6 changed files with 75 additions and 27 deletions
+17 -7
View File
@@ -1,5 +1,5 @@
#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
/*
* 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,
FsTreeWalker::CbFlag flg)
{
if (m_updfunc)
m_updfunc->update(fn);
if (m_updfunc) {
if (!m_updfunc->update(fn)) {
return FsTreeWalker::FtwStop;
}
}
// If we're changing directories, possibly adjust parameters (set
// the current directory in configuration object)
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::Status fis = FileInterner::FIAgain;
int i = 0;
while (fis == FileInterner::FIAgain) {
Rcl::Doc doc;
string ipath;
@@ -229,6 +233,12 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
if (fis == FileInterner::FIError)
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
if (doc.fmtime.empty()) {
char ascdate[20];
@@ -292,13 +302,13 @@ bool ConfIndexer::index(bool resetbefore)
if (lstat(doctopdir.c_str(), &st) < 0) {
LOGERR(("ConfIndexer::index: cant stat %s\n",
doctopdir.c_str()));
m_reason = string("Stat error for: ") + doctopdir;
m_reason = "Stat error for: " + doctopdir;
return false;
}
if (S_ISLNK(st.st_mode)) {
LOGERR(("ConfIndexer::index: no symlinks allowed in topdirs: %s\n",
doctopdir.c_str()));
m_reason = doctopdir + "is a symbolic link";
m_reason = doctopdir + " is a symbolic link";
return false;
}
}
@@ -306,7 +316,7 @@ bool ConfIndexer::index(bool resetbefore)
if (!m_config->getConfParam("dbdir", dbdir)) {
LOGERR(("ConfIndexer::index: no database directory in "
"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;
}
dbdir = path_tildexpand(dbdir);
@@ -333,7 +343,7 @@ bool ConfIndexer::index(bool resetbefore)
m_dbindexer = new DbIndexer(m_config, dbit->first, m_updfunc);
if (!m_dbindexer->indexDb(resetbefore, &dbit->second)) {
deleteZ(m_dbindexer);
m_reason = string("Failed indexing in ") + dbit->first;
m_reason = "Failed indexing in " + dbit->first;
return false;
}
deleteZ(m_dbindexer);
+4 -3
View File
@@ -16,7 +16,7 @@
*/
#ifndef _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 <list>
@@ -28,11 +28,12 @@
/* Forward decl for lower level indexing object */
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 {
public:
virtual ~DbIxStatusUpdater(){}
virtual void update(const std::string &) = 0;
virtual bool update(const std::string &) = 0;
};
/**
+20 -4
View File
@@ -1,5 +1,5 @@
#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
/*
* This program is free software; you can redistribute it and/or modify
@@ -83,11 +83,27 @@ static void cleanup()
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)
{
fprintf(stderr, "sigcleanup\n");
cleanup();
exit(1);
stopindexing = 1;
}
static const char *thisprog;
@@ -173,7 +189,7 @@ int main(int argc, const char **argv)
string lang = *argv++; argc--;
exit(!createstemdb(config, lang));
} else {
confindexer = new ConfIndexer(config);
confindexer = new ConfIndexer(config, &updater);
bool rezero(op_flags & OPT_z);
exit(!confindexer->index(rezero));
}