From 47e1f82a91ac350a54f53ea0efc69cb75fa93eeb Mon Sep 17 00:00:00 2001 From: dockes Date: Fri, 28 Apr 2006 07:54:38 +0000 Subject: [PATCH] centralize dbdir computation in rclconfig+cat with conffdir if not absolute --- src/common/rclconfig.cpp | 19 ++++++++++++++++++- src/common/rclconfig.h | 5 ++++- src/index/indexer.cpp | 6 +++--- src/index/recollindex.cpp | 13 +++++-------- src/kde/kioslave/recoll/kio_recoll.cpp | 8 ++++---- src/qtgui/main.cpp | 7 +++---- src/query/qtry.cpp | 8 ++++---- 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index bbfc4922..56175fe1 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.28 2006-04-20 09:20:09 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.29 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -272,6 +272,23 @@ string RclConfig::getMimeIconName(const string &mtype, string *path) return iconname; } +string RclConfig::getDbDir() +{ + string dbdir; + if (!getConfParam("dbdir", dbdir)) { + LOGERR(("RclConfig::getDbDir: no db directory in configuration\n")); + } else { + dbdir = path_tildexpand(dbdir); + // If not an absolute path, compute relative to config dir + if (dbdir.at(0) != '/') { + LOGDEB1(("Dbdir not abs, catting with confdir\n")); + dbdir = path_cat(m_confdir, dbdir); + } + } + LOGDEB1(("RclConfig::getDbDir: dbdir: [%s]\n", dbdir.c_str())); + return dbdir; +} + // Look up an executable filter. We look in $RECOLL_FILTERSDIR, // filtersdir in config file, then let the system use the PATH diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 2b75cd5a..129ef447 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -16,7 +16,7 @@ */ #ifndef _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_ -/* @(#$Id: rclconfig.h,v 1.19 2006-03-29 13:08:08 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: rclconfig.h,v 1.20 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes */ #include @@ -53,12 +53,15 @@ class RclConfig { bool getConfParam(const std::string &name, int *value); /** Variant with autoconversion to bool */ bool getConfParam(const std::string &name, bool *value); + /** Get default charset for current keydir (was set during setKeydir) * filenames are handled differently */ const string &getDefCharset(bool filename = false); /** Get guessCharset for current keydir (was set during setKeydir) */ bool getGuessCharset() {return guesscharset;} + /** Get database directory */ + string getDbDir(); /** * Get list of ignored suffixes from mimemap diff --git a/src/index/indexer.cpp b/src/index/indexer.cpp index 04c3f8cf..d47a32b6 100644 --- a/src/index/indexer.cpp +++ b/src/index/indexer.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: indexer.cpp,v 1.32 2006-04-25 09:59:12 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: indexer.cpp,v 1.33 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -369,13 +369,13 @@ bool ConfIndexer::index(bool resetbefore) } } m_config->setKeyDir(doctopdir); - if (!m_config->getConfParam("dbdir", dbdir)) { + dbdir = m_config->getDbDir(); + if (dbdir.empty()) { LOGERR(("ConfIndexer::index: no database directory in " "configuration for %s\n", doctopdir.c_str())); m_reason = "No database directory set for " + doctopdir; return false; } - dbdir = path_tildexpand(dbdir); dbit = dbmap.find(dbdir); if (dbit == dbmap.end()) { list l; diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index 2dce9650..3e5b6eeb 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.18 2006-04-18 08:53:27 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.19 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -48,14 +48,12 @@ static bool indexfiles(RclConfig *config, const list &filenames) // Note that we do not bother to check for multiple databases, // which are currently a fiction anyway. config->setKeyDir(path_getfather(*filenames.begin())); - string dbdir; - if (!config->getConfParam("dbdir", dbdir)) { + string dbdir = config->getDbDir(); + if (dbdir.empty()) { LOGERR(("indexfiles: no database directory in " "configuration for %s\n", filenames.begin()->c_str())); return false; } - dbdir = path_tildexpand(dbdir); - dbindexer = new DbIndexer(config, dbdir); return dbindexer->indexFiles(filenames); } @@ -65,12 +63,11 @@ static bool createstemdb(RclConfig *config, const string &lang) { // Note that we do not bother to check for multiple databases, // which are currently a fiction anyway. - string dbdir; - if (!config->getConfParam("dbdir", dbdir)) { + string dbdir = config->getDbDir(); + if (dbdir.empty()) { LOGERR(("createstemdb: no database directory in configuration\n")); return false; } - dbdir = path_tildexpand(dbdir); dbindexer = new DbIndexer(config, dbdir); return dbindexer->createStemDb(lang); } diff --git a/src/kde/kioslave/recoll/kio_recoll.cpp b/src/kde/kioslave/recoll/kio_recoll.cpp index 15bea4f4..dc444498 100644 --- a/src/kde/kioslave/recoll/kio_recoll.cpp +++ b/src/kde/kioslave/recoll/kio_recoll.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.3 2006-01-19 14:57:59 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.4 2006-04-28 07:54:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -38,14 +38,14 @@ RecollProtocol::RecollProtocol(const QCString &pool, const QCString &app) m_reason = string("Configuration problem: ") + reason; return; } - - if (m_rclconfig->getConfParam(string("dbdir"), m_dbdir) == 0) { + m_dbdir = m_rclconfig->getDbDir(); + if (m_dbdir.empty()) { // Note: this will have to be replaced by a call to a // configuration buildin dialog for initial configuration m_reason = "No db directory in configuration ??"; return; } - m_dbdir = path_tildexpand(m_dbdir); + m_rcldb = new Rcl::Db; if (!m_rcldb) { m_reason = "Could not build database object. (out of memory ?)"; diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index bb1d8313..4e8f12f7 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: main.cpp,v 1.43 2006-04-22 06:27:37 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: main.cpp,v 1.44 2006-04-28 07:54:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -195,8 +195,8 @@ int main( int argc, char ** argv ) mainWindow->sSearch->searchTypCMB->setCurrentItem(prefs.ssearchTyp); - - if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) { + dbdir = rclconfig->getDbDir(); + if (dbdir.empty()) { // Note: this will have to be replaced by a call to a // configuration buildin dialog for initial configuration QMessageBox::critical(0, "Recoll", @@ -204,7 +204,6 @@ int main( int argc, char ** argv ) "No db directory in configuration")); exit(1); } - dbdir = path_tildexpand(dbdir); rcldb = new Rcl::Db; diff --git a/src/query/qtry.cpp b/src/query/qtry.cpp index 18ce9b18..4be5973f 100644 --- a/src/query/qtry.cpp +++ b/src/query/qtry.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: qtry.cpp,v 1.7 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: qtry.cpp,v 1.8 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -86,12 +86,12 @@ int main(int argc, char **argv) if (!rclconfig->ok()) cerr << "Config could not be built" << endl; - string dbdir; - if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) { + string dbdir = rclconfig->getDbDir(); + if (dbdir.empty()) { cerr << "No database directory in configuration" << endl; exit(1); } - dbdir = path_tildexpand(dbdir); + Rcl::Db *rcldb = new Rcl::Db; if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {