separate file and document dates (mainly for email folders). Better check configuration at startup
This commit is contained in:
+20
-12
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.9 2005-10-19 14:14:17 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.10 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -32,11 +32,13 @@ RclConfig::RclConfig()
|
||||
string cfilename = confdir;
|
||||
path_cat(cfilename, "recoll.conf");
|
||||
|
||||
// Maybe we should try to open readonly here as, else, this will
|
||||
// casually create a configuration file
|
||||
conf = new ConfTree(cfilename.c_str(), 0);
|
||||
if (conf == 0) {
|
||||
cerr << "No configuration" << endl;
|
||||
// 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)) {
|
||||
reason = string("No main configuration file: ") + cfilename +
|
||||
" does not exist or cannot be parsed";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,9 +48,12 @@ RclConfig::RclConfig()
|
||||
}
|
||||
string mpath = confdir;
|
||||
path_cat(mpath, mimemapfile);
|
||||
mimemap = new ConfTree(mpath.c_str());
|
||||
if (mimemap == 0) {
|
||||
cerr << "No mime map file" << endl;
|
||||
mimemap = new ConfTree(mpath.c_str(), true);
|
||||
if (mimemap == 0 ||
|
||||
(mimemap->getStatus() != ConfSimple::STATUS_RO &&
|
||||
mimemap->getStatus() != ConfSimple::STATUS_RW)) {
|
||||
reason = string("No mime map configuration file: ") + mpath +
|
||||
" does not exist or cannot be parsed";
|
||||
return;
|
||||
}
|
||||
// mimemap->list();
|
||||
@@ -59,9 +64,12 @@ RclConfig::RclConfig()
|
||||
}
|
||||
mpath = confdir;
|
||||
path_cat(mpath, mimeconffile);
|
||||
mimeconf = new ConfTree(mpath.c_str());
|
||||
if (mimeconf == 0) {
|
||||
cerr << "No mime conf file" << endl;
|
||||
mimeconf = new ConfTree(mpath.c_str(), true);
|
||||
if (mimeconf == 0 ||
|
||||
(mimeconf->getStatus() != ConfSimple::STATUS_RO &&
|
||||
mimeconf->getStatus() != ConfSimple::STATUS_RW)) {
|
||||
reason = string("No mime configuration file: ") + mpath +
|
||||
" does not exist or cannot be parsed";
|
||||
return;
|
||||
}
|
||||
// mimeconf->list();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _RCLCONFIG_H_INCLUDED_
|
||||
#define _RCLCONFIG_H_INCLUDED_
|
||||
/* @(#$Id: rclconfig.h,v 1.5 2005-10-17 13:36:53 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rclconfig.h,v 1.6 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
class RclConfig {
|
||||
int m_ok;
|
||||
string reason; // Explanation for bad state
|
||||
string confdir; // Directory where the files are stored
|
||||
ConfTree *conf; // Parsed main configuration
|
||||
string keydir; // Current directory used for parameter fetches.
|
||||
@@ -26,7 +27,7 @@ class RclConfig {
|
||||
~RclConfig() {delete conf;delete mimemap;delete mimeconf;}
|
||||
|
||||
bool ok() {return m_ok;}
|
||||
|
||||
const string &getReason() {return reason;}
|
||||
string getConfDir() {return confdir;}
|
||||
ConfTree *getConfig() {return m_ok ? conf : 0;}
|
||||
|
||||
|
||||
+10
-4
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.1 2005-04-05 09:35:35 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.2 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -7,8 +7,10 @@ static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.1 2005-04-05 09:35:35 dockes Exp
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "rclconfig.h"
|
||||
#include "rclinit.h"
|
||||
|
||||
RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int))
|
||||
RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
||||
string &reason)
|
||||
{
|
||||
atexit(cleanup);
|
||||
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
|
||||
@@ -24,8 +26,12 @@ RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int))
|
||||
DebugLog::setfilename("stderr");
|
||||
RclConfig *config = new RclConfig;
|
||||
if (!config || !config->ok()) {
|
||||
fprintf(stderr, "Config could not be built\n");
|
||||
exit(1);
|
||||
reason = "Configuration could not be built:\n";
|
||||
if (config)
|
||||
reason += config->getReason();
|
||||
else
|
||||
reason += "Out of memory ?";
|
||||
return 0;
|
||||
}
|
||||
|
||||
string logfilename, loglevel;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef _RCLINIT_H_INCLUDED_
|
||||
#define _RCLINIT_H_INCLUDED_
|
||||
/* @(#$Id: rclinit.h,v 1.1 2005-04-05 09:35:35 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rclinit.h,v 1.2 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
class RclConfig;
|
||||
|
||||
extern RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int));
|
||||
extern RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
||||
std::string &reason);
|
||||
|
||||
#endif /* _RCLINIT_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user