small cleanups and add option to call beaglequeue
This commit is contained in:
parent
683f76e6a5
commit
bad98d6ee5
@ -41,12 +41,23 @@ using namespace std;
|
|||||||
#include "x11mon.h"
|
#include "x11mon.h"
|
||||||
#include "cancelcheck.h"
|
#include "cancelcheck.h"
|
||||||
#include "rcldb.h"
|
#include "rcldb.h"
|
||||||
|
#include "beaglequeue.h"
|
||||||
|
|
||||||
// Globals for exit cleanup
|
// Globals for atexit cleanup
|
||||||
ConfIndexer *confindexer;
|
static ConfIndexer *confindexer;
|
||||||
DbIndexer *dbindexer;
|
static DbIndexer *dbindexer;
|
||||||
|
|
||||||
|
// This is set as an atexit routine,
|
||||||
|
static void cleanup()
|
||||||
|
{
|
||||||
|
deleteZ(confindexer);
|
||||||
|
deleteZ(dbindexer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Global stop request flag. This is checked in a number of place in the
|
||||||
|
// indexing routines.
|
||||||
int stopindexing;
|
int stopindexing;
|
||||||
|
|
||||||
// Mainly used to request indexing stop, we currently do not use the
|
// Mainly used to request indexing stop, we currently do not use the
|
||||||
// current file name
|
// current file name
|
||||||
class MyUpdater : public DbIxStatusUpdater {
|
class MyUpdater : public DbIxStatusUpdater {
|
||||||
@ -58,41 +69,34 @@ class MyUpdater : public DbIxStatusUpdater {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MyUpdater updater;
|
static MyUpdater updater;
|
||||||
|
|
||||||
static void sigcleanup(int sig)
|
static void sigcleanup(int sig)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "sigcleanup\n");
|
fprintf(stderr, "Got signal, registering stop request\n");
|
||||||
LOGDEB(("sigcleanup\n"));
|
LOGDEB(("Got signal, registering stop request\n"));
|
||||||
CancelCheck::instance().setCancel();
|
CancelCheck::instance().setCancel();
|
||||||
stopindexing = 1;
|
stopindexing = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool makeDbIndexer(RclConfig *config)
|
static bool makeDbIndexer(RclConfig *config)
|
||||||
{
|
{
|
||||||
string dbdir = config->getDbDir();
|
|
||||||
if (dbdir.empty()) {
|
|
||||||
fprintf(stderr, "makeDbIndexer: no database directory in "
|
|
||||||
"configuration for %s\n", config->getKeyDir().c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Check if there is already an indexer for the right db
|
|
||||||
if (dbindexer && dbindexer->getDbDir().compare(dbdir)) {
|
|
||||||
deleteZ(dbindexer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbindexer)
|
if (!dbindexer)
|
||||||
dbindexer = new DbIndexer(config, dbdir, &updater);
|
dbindexer = new DbIndexer(config, &updater);
|
||||||
|
return dbindexer ? true : false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The list of top directories/files wont change during program run,
|
// The list of top directories/files wont change during program run,
|
||||||
// let's cache it:
|
// let's cache it:
|
||||||
static list<string> o_tdl;
|
static list<string> o_tdl;
|
||||||
|
|
||||||
// Index a list of files. We just check that they belong to one of the topdirs
|
// Index a list of files. We just check that they belong to one of the
|
||||||
// subtrees, and call the indexer method
|
// topdirs subtrees, and call the indexer method.
|
||||||
|
//
|
||||||
|
// This is called either from the command line or from the monitor. In
|
||||||
|
// this case we're called repeatedly in the same process, and the
|
||||||
|
// dbIndexer is only created once by makeDbIndexer (but the db is
|
||||||
|
// flushed anyway)
|
||||||
bool indexfiles(RclConfig *config, const list<string> &filenames)
|
bool indexfiles(RclConfig *config, const list<string> &filenames)
|
||||||
{
|
{
|
||||||
if (filenames.empty())
|
if (filenames.empty())
|
||||||
@ -135,13 +139,13 @@ bool indexfiles(RclConfig *config, const list<string> &filenames)
|
|||||||
// go:
|
// go:
|
||||||
config->setKeyDir(path_getfather(*myfiles.begin()));
|
config->setKeyDir(path_getfather(*myfiles.begin()));
|
||||||
|
|
||||||
if (!makeDbIndexer(config) || !dbindexer)
|
if (!makeDbIndexer(config))
|
||||||
return false;
|
return false;
|
||||||
else
|
|
||||||
return dbindexer->indexFiles(myfiles);
|
return dbindexer->indexFiles(myfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a list of files.
|
// Delete a list of files. Same comments about call contexts as indexfiles.
|
||||||
bool purgefiles(RclConfig *config, const list<string> &filenames)
|
bool purgefiles(RclConfig *config, const list<string> &filenames)
|
||||||
{
|
{
|
||||||
if (filenames.empty())
|
if (filenames.empty())
|
||||||
@ -169,16 +173,15 @@ bool purgefiles(RclConfig *config, const list<string> &filenames)
|
|||||||
// go:
|
// go:
|
||||||
config->setKeyDir(path_getfather(*myfiles.begin()));
|
config->setKeyDir(path_getfather(*myfiles.begin()));
|
||||||
|
|
||||||
if (!makeDbIndexer(config) || !dbindexer)
|
if (!makeDbIndexer(config))
|
||||||
return false;
|
return false;
|
||||||
else
|
return dbindexer->purgeFiles(myfiles);
|
||||||
return dbindexer->purgeFiles(myfiles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create stemming and spelling databases
|
// Create stemming and spelling databases
|
||||||
bool createAuxDbs(RclConfig *config)
|
bool createAuxDbs(RclConfig *config)
|
||||||
{
|
{
|
||||||
if (!makeDbIndexer(config) || !dbindexer)
|
if (!makeDbIndexer(config))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!dbindexer->createStemmingDatabases())
|
if (!dbindexer->createStemmingDatabases())
|
||||||
@ -193,17 +196,9 @@ bool createAuxDbs(RclConfig *config)
|
|||||||
// Create additional stem database
|
// Create additional stem database
|
||||||
static bool createstemdb(RclConfig *config, const string &lang)
|
static bool createstemdb(RclConfig *config, const string &lang)
|
||||||
{
|
{
|
||||||
makeDbIndexer(config);
|
if (!makeDbIndexer(config))
|
||||||
if (dbindexer)
|
return false;
|
||||||
return dbindexer->createStemDb(lang);
|
return dbindexer->createStemDb(lang);
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup()
|
|
||||||
{
|
|
||||||
deleteZ(confindexer);
|
|
||||||
deleteZ(dbindexer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *thisprog;
|
static const char *thisprog;
|
||||||
@ -221,6 +216,7 @@ static int op_flags;
|
|||||||
#define OPT_w 0x400
|
#define OPT_w 0x400
|
||||||
#define OPT_x 0x800
|
#define OPT_x 0x800
|
||||||
#define OPT_l 0x1000
|
#define OPT_l 0x1000
|
||||||
|
#define OPT_b 0x2000
|
||||||
|
|
||||||
static const char usage [] =
|
static const char usage [] =
|
||||||
"\n"
|
"\n"
|
||||||
@ -243,6 +239,8 @@ static const char usage [] =
|
|||||||
" List available stemming languages\n"
|
" List available stemming languages\n"
|
||||||
"recollindex -s <lang>\n"
|
"recollindex -s <lang>\n"
|
||||||
" Build stem database for additional language <lang>\n"
|
" Build stem database for additional language <lang>\n"
|
||||||
|
"recollindex -b\n"
|
||||||
|
" Process the Beagle queue\n"
|
||||||
#ifdef RCL_USE_ASPELL
|
#ifdef RCL_USE_ASPELL
|
||||||
"recollindex -S\n"
|
"recollindex -S\n"
|
||||||
" Build aspell spelling dictionary.>\n"
|
" Build aspell spelling dictionary.>\n"
|
||||||
@ -280,6 +278,7 @@ int main(int argc, const char **argv)
|
|||||||
Usage();
|
Usage();
|
||||||
while (**argv)
|
while (**argv)
|
||||||
switch (*(*argv)++) {
|
switch (*(*argv)++) {
|
||||||
|
case 'b': op_flags |= OPT_b; break;
|
||||||
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
||||||
a_config = *(++argv);
|
a_config = *(++argv);
|
||||||
argc--; goto b1;
|
argc--; goto b1;
|
||||||
@ -396,18 +395,19 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
#ifdef RCL_USE_ASPELL
|
#ifdef RCL_USE_ASPELL
|
||||||
} else if (op_flags & OPT_S) {
|
} else if (op_flags & OPT_S) {
|
||||||
makeDbIndexer(config);
|
if (!makeDbIndexer(config))
|
||||||
if (dbindexer)
|
exit(1);
|
||||||
exit(!dbindexer->createAspellDict());
|
exit(!dbindexer->createAspellDict());
|
||||||
else
|
|
||||||
exit(1);
|
|
||||||
#endif // ASPELL
|
#endif // ASPELL
|
||||||
|
} else if (op_flags & OPT_b) {
|
||||||
|
BeagleQueueIndexer beagler(config);
|
||||||
|
bool status = beagler.processqueue();
|
||||||
|
return !status;
|
||||||
} else {
|
} else {
|
||||||
confindexer = new ConfIndexer(config, &updater);
|
confindexer = new ConfIndexer(config, &updater);
|
||||||
bool status = confindexer->index(rezero);
|
bool status = confindexer->index(rezero);
|
||||||
if (!status)
|
if (!status)
|
||||||
cerr << "Indexing failed" << endl;
|
cerr << "Indexing failed" << endl;
|
||||||
exit(!status);
|
return !status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user