From f3820471e410860fbe23120bd438f8b521201a3c Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 8 Apr 2016 15:09:15 +0200 Subject: [PATCH] Add cachedir variable allowing to move all data directories by setting a single value. Closes issue #270 --- src/aspell/rclaspell.cpp | 12 +------ src/common/beaglequeuecache.cpp | 9 +----- src/common/rclconfig.cpp | 57 ++++++++++++++++++++++++++++----- src/common/rclconfig.h | 12 ++++++- src/doc/user/usermanual.xml | 26 ++++++++++++++- src/internfile/mh_mbox.cpp | 8 +---- src/sampleconf/recoll.conf | 27 +++++++++++++--- 7 files changed, 110 insertions(+), 41 deletions(-) diff --git a/src/aspell/rclaspell.cpp b/src/aspell/rclaspell.cpp index 14cfd856..9d7a3d2f 100644 --- a/src/aspell/rclaspell.cpp +++ b/src/aspell/rclaspell.cpp @@ -220,17 +220,7 @@ bool Aspell::ok() const string Aspell::dicPath() { - string ccdir; - m_config->getConfParam("aspellDicDir", ccdir); - if (ccdir.empty()) { - ccdir = m_config->getConfDir(); - } else { - ccdir = path_tildexpand(ccdir); - // If not an absolute path, compute relative to config dir - if (!path_isabsolute(ccdir)) - ccdir = path_cat(m_config->getConfDir(), ccdir); - } - + string ccdir = m_config->getAspellcacheDir(); return path_cat(ccdir, string("aspdict.") + m_lang + string(".rws")); } diff --git a/src/common/beaglequeuecache.cpp b/src/common/beaglequeuecache.cpp index 99b165b5..2f82dd1b 100644 --- a/src/common/beaglequeuecache.cpp +++ b/src/common/beaglequeuecache.cpp @@ -29,14 +29,7 @@ const string cstr_bgc_mimetype("mimetype"); BeagleQueueCache::BeagleQueueCache(RclConfig *cnf) { - string ccdir; - cnf->getConfParam("webcachedir", ccdir); - if (ccdir.empty()) - ccdir = "webcache"; - ccdir = path_tildexpand(ccdir); - // If not an absolute path, compute relative to config dir - if (!path_isabsolute(ccdir)) - ccdir = path_cat(cnf->getConfDir(), ccdir); + string ccdir = cnf->getWebcacheDir(); int maxmbs = 40; cnf->getConfParam("webcachemaxmbs", &maxmbs); diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index a26de74b..6fcad3da 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -337,6 +337,9 @@ bool RclConfig::updateMainConfig() m_index_stripchars_init = 1; } + if (getConfParam("cachedir", m_cachedir)) { + m_cachedir = path_canon(path_tildexpand(m_cachedir)); + } return true; } @@ -810,7 +813,7 @@ bool RclConfig::getMissingHelperDesc(string& out) const void RclConfig::storeMissingHelperDesc(const string &s) { - string fmiss = path_cat(getConfDir(), "missing"); + string fmiss = path_cat(getCacheDir(), "missing"); FILE *fp = fopen(fmiss.c_str(), "w"); if (fp) { if (s.size() > 0 && fwrite(s.c_str(), s.size(), 1, fp) != 1) { @@ -1147,9 +1150,43 @@ string RclConfig::getConfdirPath(const char *varname, const char *dflt) const } +string RclConfig::getCacheDir() const +{ + return m_cachedir.empty() ? getConfDir() : m_cachedir; +} + +// Return path defined by varname. May be absolute or relative to +// confdir, with default in confdir +string RclConfig::getCachedirPath(const char *varname, const char *dflt) const +{ + string result; + if (!getConfParam(varname, result)) { + result = path_cat(getCacheDir(), dflt); + } else { + result = path_tildexpand(result); + // If not an absolute path, compute relative to cache dir + if (!path_isabsolute(result)) { + result = path_cat(getCacheDir(), result); + } + } + return path_canon(result); +} + string RclConfig::getDbDir() const { - return getConfdirPath("dbdir", "xapiandb"); + return getCachedirPath("dbdir", "xapiandb"); +} +string RclConfig::getWebcacheDir() const +{ + return getCachedirPath("webcachedir", "webcache"); +} +string RclConfig::getMboxcacheDir() const +{ + return getCachedirPath("mboxcachedir", "mboxcache"); +} +string RclConfig::getAspellcacheDir() const +{ + return getCachedirPath("aspellDicDir", ""); } string RclConfig::getStopfile() const @@ -1164,9 +1201,14 @@ string RclConfig::getSynGroupsFile() const // The index status file is fast changing, so it's possible to put it outside // of the config directory (for ssds, not sure this is really useful). +// To enable being quite xdg-correct we should add a getRundirPath() string RclConfig::getIdxStatusFile() const { - return getConfdirPath("idxstatusfile", "idxstatus.txt"); + return getCachedirPath("idxstatusfile", "idxstatus.txt"); +} +string RclConfig::getPidfile() const +{ + return path_cat(getCacheDir(), "index.pid"); } void RclConfig::urlrewrite(const string& dbdir, string& url) const @@ -1221,11 +1263,6 @@ bool RclConfig::sourceChanged() const return false; } -string RclConfig::getPidfile() const -{ - return path_cat(getConfDir(), "index.pid"); -} - string RclConfig::getWebQueueDir() const { string webqueuedir; @@ -1253,6 +1290,9 @@ vector RclConfig::getSkippedPaths() const // don't do this. skpl.push_back(getDbDir()); skpl.push_back(getConfDir()); + if (getCacheDir().compare(getConfDir())) { + skpl.push_back(getCacheDir()); + } // And the web queue dir skpl.push_back(getWebQueueDir()); for (vector::iterator it = skpl.begin(); it != skpl.end(); it++) { @@ -1457,6 +1497,7 @@ void RclConfig::initFrom(const RclConfig& r) return; m_reason = r.m_reason; m_confdir = r.m_confdir; + m_cachedir = r.m_cachedir; m_datadir = r.m_datadir; m_keydir = r.m_keydir; m_cdirs = r.m_cdirs; diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 91117143..0ebc4afe 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -109,6 +109,7 @@ class RclConfig { * constructor it it is the default one (~/.recoll) and it did * not exist yet. */ string getConfDir() const {return m_confdir;} + string getCacheDir() const; /** Check if the config files were modified since we read them */ bool sourceChanged() const; @@ -172,8 +173,12 @@ class RclConfig { vector getTopdirs() const; string getConfdirPath(const char *varname, const char *dflt) const; - /** Get database directory */ + string getCachedirPath(const char *varname, const char *dflt) const; + /** Get database and other directories */ string getDbDir() const; + string getWebcacheDir() const; + string getMboxcacheDir() const; + string getAspellcacheDir() const; /** Get stoplist file name */ string getStopfile() const; /** Get synonym groups file name */ @@ -333,6 +338,11 @@ class RclConfig { int m_ok; string m_reason; // Explanation for bad state string m_confdir; // User directory where the customized files are stored + // Normally same as confdir. Set to store all bulk data elsewhere. + // Provides defaults top location for dbdir, webcachedir, + // mboxcachedir, aspellDictDir, which can still be used to + // override. + string m_cachedir; string m_datadir; // Example: /usr/local/share/recoll string m_keydir; // Current directory used for parameter fetches. int m_keydirgen; // To help with knowing when to update computed data. diff --git a/src/doc/user/usermanual.xml b/src/doc/user/usermanual.xml index b706fdae..75252cd9 100644 --- a/src/doc/user/usermanual.xml +++ b/src/doc/user/usermanual.xml @@ -5982,7 +5982,31 @@ field2 = value for field2 Parameters affecting where and how we store things: - + + + + cachedir + + When not explicitly specified, the &RCL; data directories + are stored relative to the configuration directory. If + cachedir is set, the directories are stored + under the specified value instead (e.g. if + cachedir is set to + ~/.cache/recoll, the default + dbdir would be + ~/.cache/recoll/xapiandb instead of + ~/.recoll/xapiandb ). This affects the + default values for dbdir, + webcachedir, + mboxcachedir, and + aspellDicDir, which can still be + individually specified to override + cachedir. Note that if you have multiple + configurations, each must have a different + cachedir. + + + dbdir The name of the Xapian data directory. It will be created if needed when the index is diff --git a/src/internfile/mh_mbox.cpp b/src/internfile/mh_mbox.cpp index 32a72452..0032f9a3 100644 --- a/src/internfile/mh_mbox.cpp +++ b/src/internfile/mh_mbox.cpp @@ -196,13 +196,7 @@ public: } m_minfsize = minmbs * 1000 * 1000; - config->getConfParam("mboxcachedir", m_dir); - if (m_dir.empty()) - m_dir = "mboxcache"; - m_dir = path_tildexpand(m_dir); - // If not an absolute path, compute relative to config dir - if (!path_isabsolute(m_dir)) - m_dir = path_cat(config->getConfDir(), m_dir); + m_dir = config->getMboxcacheDir(); m_ok = true; } return m_ok; diff --git a/src/sampleconf/recoll.conf b/src/sampleconf/recoll.conf index 3518976a..7cfac94f 100644 --- a/src/sampleconf/recoll.conf +++ b/src/sampleconf/recoll.conf @@ -153,10 +153,21 @@ maxTermExpand = 10000 # eating all the memory. Default 50000 maxXapianClauses = 50000 +# Recoll data directories are normally stored relative to the configuration +# directory (e.g. ~/.recoll/xapiandb, ~/.recoll/mboxcache). If this is set, +# the directories are stored under the specified value instead +# (e.g. if cachedir is ~/.cache/recoll, the default dbdir would be +# ~/.cache/recoll/xapiandb). +# This affects dbdir, webcachedir, mboxcachedir, aspellDicDir, which can +# still be individually specified to override cachedir. +# Note that if you have multiple configurations, each must have a different +# cachedir, there is no automatic computation of a subpath under cachedir. +#cachedir = ~/.cache/recoll + # Where to store the database (directory). This may be an absolute path, -# else it is taken as relative to the configuration directory (-c argument -# or $RECOLL_CONFDIR). -# If nothing is specified, the default is then ~/.recoll/xapiandb/ +# else it is taken as relative to cachedir if set, or the configuration +# directory (-c argument or $RECOLL_CONFDIR). If nothing is specified, the +# default is then ~/.recoll/xapiandb/ dbdir = xapiandb # Indexing process threads configuration. If Recoll is configured for @@ -289,6 +300,11 @@ filtermaxmbytes = 2000 # Jessie). See Debian bug 772415 # aspellAddCreateParam = --local-data-dir=/usr/lib/aspell +# The aspell dictionary (aspdict.(lang).rws) is normally stored in the +# directory specified by cachedir if set, or under the configuration +# directory. Set the following to change: +#aspellDicDir = + # You may also want to set this to have a look at aspell dictionary # creation errors. But there are always many, so this is mostly for debugging # aspellKeepStderr = 1 @@ -329,7 +345,7 @@ processwebqueue = 0 #webqueuedir = ~/.recollweb/ToIndex # This is only used by the web history indexing code, and # defines where the cache for visited pages will live. Default: -# $RECOLL_CONFDIR/webcache +# cachedir/webcache if cachedir is set, else $RECOLL_CONFDIR/webcache webcachedir = webcache # This is only used by the web history indexing code, and # defines the maximum size for the web page cache. Default: 40 MB. @@ -337,7 +353,8 @@ webcachedir = webcache webcachemaxmbs = 40 # The directory where mbox message offsets cache files are held. This is -# normally $RECOLL_CONFDIR/mboxcache, but it may be useful to share a +# normally named mboxcache under cachedir if set, or else under the +# configuration directory, but it may be useful to share a # directory between different configurations. #mboxcachedir = mboxcache