From c7f5318e434f74e72686a5f3c30245798b578847 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 8 Jun 2015 13:20:06 +0200 Subject: [PATCH] config checking: only test skippedPaths existence for user-added values, not defaults --- src/common/rclconfig.cpp | 18 ++++++++++-------- src/common/rclconfig.h | 16 ++++++++++------ src/index/recollindex.cpp | 6 ++++-- src/utils/conftree.h | 8 +++++++- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index ad5e11e4..3f915452 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -380,10 +380,10 @@ void RclConfig::setKeyDir(const string &dir) m_defcharset.erase(); } -bool RclConfig::getConfParam(const string &name, int *ivp) const +bool RclConfig::getConfParam(const string &name, int *ivp, bool shallow) const { string value; - if (!getConfParam(name, value)) + if (!getConfParam(name, value, shallow)) return false; errno = 0; long lval = strtol(value.c_str(), 0, 0); @@ -394,37 +394,39 @@ bool RclConfig::getConfParam(const string &name, int *ivp) const return true; } -bool RclConfig::getConfParam(const string &name, bool *bvp) const +bool RclConfig::getConfParam(const string &name, bool *bvp, bool shallow) const { if (!bvp) return false; *bvp = false; string s; - if (!getConfParam(name, s)) + if (!getConfParam(name, s, shallow)) return false; *bvp = stringToBool(s); return true; } -bool RclConfig::getConfParam(const string &name, vector *svvp) const +bool RclConfig::getConfParam(const string &name, vector *svvp, + bool shallow) const { if (!svvp) return false; svvp->clear(); string s; - if (!getConfParam(name, s)) + if (!getConfParam(name, s, shallow)) return false; return stringToStrings(s, *svvp); } -bool RclConfig::getConfParam(const string &name, vector *vip) const +bool RclConfig::getConfParam(const string &name, vector *vip, + bool shallow) const { if (!vip) return false; vip->clear(); vector vs; - if (!getConfParam(name, &vs)) + if (!getConfParam(name, &vs, shallow)) return false; vip->reserve(vs.size()); for (unsigned int i = 0; i < vs.size(); i++) { diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 6e470517..f305b0ec 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -123,21 +123,25 @@ class RclConfig { string getKeyDir() const {return m_keydir;} /** Get generic configuration parameter according to current keydir */ - bool getConfParam(const string &name, string &value) const + bool getConfParam(const string &name, string &value, + bool shallow=false) const { if (m_conf == 0) return false; - return m_conf->get(name, value, m_keydir); + return m_conf->get(name, value, m_keydir, shallow); } /** Variant with autoconversion to int */ - bool getConfParam(const string &name, int *value) const; + bool getConfParam(const string &name, int *value, bool shallow=false) const; /** Variant with autoconversion to bool */ - bool getConfParam(const string &name, bool *value) const; + bool getConfParam(const string &name, bool *value, + bool shallow=false) const; /** Variant with conversion to vector * (stringToStrings). Can fail if the string is malformed. */ - bool getConfParam(const string &name, vector *value) const; + bool getConfParam(const string &name, vector *value, + bool shallow=false) const; /** Variant with conversion to vector */ - bool getConfParam(const string &name, vector *value) const; + bool getConfParam(const string &name, vector *value, + bool shallow=false) const; enum ThrStage {ThrIntern=0, ThrSplit=1, ThrDbWrite=2}; pair getThrConf(ThrStage who) const; diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index f79cf4a1..7044d103 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -284,7 +284,9 @@ static bool checktopdirs(RclConfig *config, vector& nonexist) } } - if (config->getConfParam("skippedPaths", &tdl)) { + // Check skippedPaths too, but only the user part (shallow==true), not + // the default values (e.g. /media, which might not exist). + if (config->getConfParam("skippedPaths", &tdl, true)) { for (vector::iterator it = tdl.begin(); it != tdl.end(); it++) { *it = path_tildexpand(*it); if (access(it->c_str(), 0) < 0) { @@ -293,7 +295,7 @@ static bool checktopdirs(RclConfig *config, vector& nonexist) } } - if (config->getConfParam("daemSkippedPaths", &tdl)) { + if (config->getConfParam("daemSkippedPaths", &tdl, true)) { for (vector::iterator it = tdl.begin(); it != tdl.end(); it++) { *it = path_tildexpand(*it); if (access(it->c_str(), 0) < 0) { diff --git a/src/utils/conftree.h b/src/utils/conftree.h index 08d316c1..7ea85a69 100644 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -399,15 +399,21 @@ public: return false; } - virtual int get(const string &name, string &value, const string &sk) const + virtual int get(const string &name, string &value, const string &sk, + bool shallow) const { typename vector::const_iterator it; for (it = m_confs.begin();it != m_confs.end();it++) { if ((*it)->get(name, value, sk)) return true; + if (shallow) + break; } return false; } + virtual int get(const string &name, string &value, const string &sk) const { + return get(name, value, sk, false); + } virtual bool hasNameAnywhere(const string& nm) const {