slight config cleanup
This commit is contained in:
+55
-34
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.18 2006-01-10 12:58:39 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.19 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@@ -23,13 +23,11 @@ using namespace std;
|
||||
static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf"};
|
||||
static int ncffiles = sizeof(configfiles) / sizeof(char *);
|
||||
|
||||
static bool createConfig(string &reason)
|
||||
static bool createConfig(const string &datadir, string &reason)
|
||||
{
|
||||
const char *cprefix = getenv("RECOLL_PREFIX");
|
||||
if (cprefix == 0)
|
||||
cprefix = RECOLL_PREFIX;
|
||||
string prefix = path_cat(cprefix, "share/recoll/examples");
|
||||
|
||||
// Samples directory
|
||||
string exdir = path_cat(datadir, "examples");
|
||||
// User's
|
||||
string recolldir = path_tildexpand("~/.recoll");
|
||||
if (mkdir(recolldir.c_str(), 0755) < 0) {
|
||||
reason += string("mkdir(") + recolldir + ") failed: " +
|
||||
@@ -37,7 +35,7 @@ static bool createConfig(string &reason)
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < ncffiles; i++) {
|
||||
string src = path_cat((const string&)prefix, string(configfiles[i]));
|
||||
string src = path_cat((const string&)exdir, string(configfiles[i]));
|
||||
string dst = path_cat((const string&)recolldir, string(configfiles[i]));
|
||||
if (!copyfile(src.c_str(), dst.c_str(), reason)) {
|
||||
LOGERR(("Copyfile failed: %s\n", reason.c_str()));
|
||||
@@ -49,8 +47,8 @@ static bool createConfig(string &reason)
|
||||
|
||||
|
||||
RclConfig::RclConfig()
|
||||
: m_ok(false), conf(0), mimemap(0), mimeconf(0), stopsuffixes(0)
|
||||
|
||||
: m_ok(false), m_conf(0), mimemap(0), mimeconf(0), mimemap_local(0),
|
||||
stopsuffixes(0)
|
||||
{
|
||||
static int loginit = 0;
|
||||
if (!loginit) {
|
||||
@@ -59,35 +57,45 @@ RclConfig::RclConfig()
|
||||
loginit = 1;
|
||||
}
|
||||
|
||||
// Compute our data dir name, typically /usr/local/share/recoll
|
||||
const char *cdatadir = getenv("RECOLL_DATADIR");
|
||||
if (cdatadir == 0) {
|
||||
// If not in environment, use the compiled-in constant.
|
||||
m_datadir = RECOLL_DATADIR;
|
||||
} else {
|
||||
m_datadir = cdatadir;
|
||||
}
|
||||
|
||||
const char *cp = getenv("RECOLL_CONFDIR");
|
||||
if (cp) {
|
||||
confdir = cp;
|
||||
m_confdir = cp;
|
||||
} else {
|
||||
confdir = path_home();
|
||||
confdir += ".recoll/";
|
||||
m_confdir = path_home();
|
||||
m_confdir += ".recoll/";
|
||||
}
|
||||
string cfilename = path_cat(confdir, "recoll.conf");
|
||||
string cfilename = path_cat(m_confdir, "recoll.conf");
|
||||
|
||||
if (access(confdir.c_str(), 0) != 0 || access(cfilename.c_str(), 0) != 0) {
|
||||
if (!createConfig(reason))
|
||||
if (access(m_confdir.c_str(), 0) != 0 ||
|
||||
access(cfilename.c_str(), 0) != 0) {
|
||||
if (!createConfig(m_datadir, reason))
|
||||
return;
|
||||
}
|
||||
|
||||
// Open readonly here so as not to casually create a config file
|
||||
conf = new ConfTree(cfilename.c_str(), true);
|
||||
if (conf == 0 ||
|
||||
(conf->getStatus() != ConfSimple::STATUS_RO &&
|
||||
conf->getStatus() != ConfSimple::STATUS_RW)) {
|
||||
m_conf = new ConfTree(cfilename.c_str(), true);
|
||||
if (m_conf == 0 ||
|
||||
(m_conf->getStatus() != ConfSimple::STATUS_RO &&
|
||||
m_conf->getStatus() != ConfSimple::STATUS_RW)) {
|
||||
reason = string("No main configuration file: ") + cfilename +
|
||||
" does not exist or cannot be parsed";
|
||||
return;
|
||||
}
|
||||
|
||||
string mimemapfile;
|
||||
if (!conf->get("mimemapfile", mimemapfile, "")) {
|
||||
if (!m_conf->get("mimemapfile", mimemapfile, "")) {
|
||||
mimemapfile = "mimemap";
|
||||
}
|
||||
string mpath = path_cat(confdir, mimemapfile);
|
||||
string mpath = path_cat(m_confdir, mimemapfile);
|
||||
mimemap = new ConfTree(mpath.c_str(), true);
|
||||
if (mimemap == 0 ||
|
||||
(mimemap->getStatus() != ConfSimple::STATUS_RO &&
|
||||
@@ -99,10 +107,10 @@ RclConfig::RclConfig()
|
||||
// mimemap->list();
|
||||
|
||||
string mimeconffile;
|
||||
if (!conf->get("mimeconffile", mimeconffile, "")) {
|
||||
if (!m_conf->get("mimeconffile", mimeconffile, "")) {
|
||||
mimeconffile = "mimeconf";
|
||||
}
|
||||
mpath = path_cat(confdir, mimeconffile);
|
||||
mpath = path_cat(m_confdir, mimeconffile);
|
||||
mimeconf = new ConfTree(mpath.c_str(), true);
|
||||
if (mimeconf == 0 ||
|
||||
(mimeconf->getStatus() != ConfSimple::STATUS_RO &&
|
||||
@@ -210,10 +218,9 @@ string RclConfig::getMimeIconName(const string &mtype)
|
||||
return hs;
|
||||
}
|
||||
|
||||
// Look up an executable filter.
|
||||
// We look in RECOLL_FILTERSDIR, filtersdir param, then
|
||||
// let the system use the PATH
|
||||
string find_filter(RclConfig *conf, const string &icmd)
|
||||
// Look up an executable filter. We look in $RECOLL_FILTERSDIR,
|
||||
// filtersdir in config file, then let the system use the PATH
|
||||
string RclConfig::findFilter(const string &icmd)
|
||||
{
|
||||
// If the path is absolute, this is it
|
||||
if (icmd[0] == '/')
|
||||
@@ -222,19 +229,33 @@ string find_filter(RclConfig *conf, const string &icmd)
|
||||
string cmd;
|
||||
const char *cp;
|
||||
|
||||
// Filters dir from environment ?
|
||||
if ((cp = getenv("RECOLL_FILTERSDIR"))) {
|
||||
cmd = path_cat(cp, icmd);
|
||||
if (access(cmd.c_str(), X_OK) == 0)
|
||||
return cmd;
|
||||
} else if (conf->getConfParam(string("filtersdir"), cmd)) {
|
||||
}
|
||||
// Filters dir as configuration parameter?
|
||||
if (getConfParam(string("filtersdir"), cmd)) {
|
||||
cmd = path_cat(cmd, icmd);
|
||||
if (access(cmd.c_str(), X_OK) == 0)
|
||||
return cmd;
|
||||
} else {
|
||||
cmd = path_cat(conf->getConfDir(), icmd);
|
||||
if (access(cmd.c_str(), X_OK) == 0)
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
// Filters dir as datadir subdir. Actually the standard case, but
|
||||
// this is normally the same value found in config file (previous step)
|
||||
cmd = path_cat(m_datadir, "filters");
|
||||
cmd = path_cat(cmd, icmd);
|
||||
if (access(cmd.c_str(), X_OK) == 0)
|
||||
return cmd;
|
||||
|
||||
// Last resort for historical reasons: check in personal config
|
||||
// directory
|
||||
cmd = path_cat(getConfDir(), icmd);
|
||||
if (access(cmd.c_str(), X_OK) == 0)
|
||||
return cmd;
|
||||
|
||||
// Let the shell try to find it...
|
||||
return icmd;
|
||||
}
|
||||
|
||||
|
||||
+18
-10
@@ -1,6 +1,6 @@
|
||||
#ifndef _RCLCONFIG_H_INCLUDED_
|
||||
#define _RCLCONFIG_H_INCLUDED_
|
||||
/* @(#$Id: rclconfig.h,v 1.11 2006-01-10 11:07:21 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rclconfig.h,v 1.12 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -11,19 +11,25 @@ class RclConfig {
|
||||
public:
|
||||
|
||||
RclConfig();
|
||||
~RclConfig() {delete conf;delete mimemap;delete mimeconf;}
|
||||
~RclConfig() {
|
||||
delete m_conf;
|
||||
delete mimemap;
|
||||
delete mimeconf;
|
||||
delete mimemap_local;
|
||||
delete stopsuffixes;
|
||||
}
|
||||
|
||||
bool ok() {return m_ok;}
|
||||
const string &getReason() {return reason;}
|
||||
string getConfDir() {return confdir;}
|
||||
string getConfDir() {return m_confdir;}
|
||||
//ConfTree *getConfig() {return m_ok ? conf : 0;}
|
||||
|
||||
/// Get generic configuration parameter according to current keydir
|
||||
bool getConfParam(const string &name, string &value)
|
||||
{
|
||||
if (conf == 0)
|
||||
if (m_conf == 0)
|
||||
return false;
|
||||
return conf->get(name, value, keydir);
|
||||
return m_conf->get(name, value, keydir);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -36,9 +42,9 @@ class RclConfig {
|
||||
void setKeyDir(const string &dir)
|
||||
{
|
||||
keydir = dir;
|
||||
conf->get("defaultcharset", defcharset, keydir);
|
||||
m_conf->get("defaultcharset", defcharset, keydir);
|
||||
string str;
|
||||
conf->get("guesscharset", str, keydir);
|
||||
m_conf->get("guesscharset", str, keydir);
|
||||
guesscharset = stringToBool(str);
|
||||
}
|
||||
|
||||
@@ -65,11 +71,14 @@ class RclConfig {
|
||||
bool getGuessCharset() {return guesscharset;}
|
||||
std::list<string> getAllMimeTypes();
|
||||
|
||||
std::string findFilter(const std::string& cmd);
|
||||
|
||||
private:
|
||||
int m_ok;
|
||||
string reason; // Explanation for bad state
|
||||
string confdir; // Directory where the files are stored
|
||||
ConfTree *conf; // Parsed main configuration
|
||||
string m_confdir; // Directory where the files are stored
|
||||
string m_datadir; // Example: /usr/local/share/recoll
|
||||
ConfTree *m_conf; // Parsed main configuration
|
||||
string keydir; // Current directory used for parameter fetches.
|
||||
|
||||
ConfTree *mimemap; // These are independant of current keydir.
|
||||
@@ -82,6 +91,5 @@ class RclConfig {
|
||||
bool guesscharset; // They are fetched initially or on setKeydir()
|
||||
};
|
||||
|
||||
std::string find_filter(RclConfig *conf, const string& cmd);
|
||||
|
||||
#endif /* _RCLCONFIG_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user