Allow defining monitordirs variable: subset/dir of topdirs which will get monitored for updates
This commit is contained in:
parent
68e6b9f8d0
commit
8559572c7e
@ -585,18 +585,24 @@ pair<int,int> RclConfig::getThrConf(ThrStage who) const
|
|||||||
return m_thrConf[who];
|
return m_thrConf[who];
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> RclConfig::getTopdirs() const
|
vector<string> RclConfig::getTopdirs(bool formonitor) const
|
||||||
{
|
{
|
||||||
vector<string> tdl;
|
vector<string> tdl;
|
||||||
if (!getConfParam("topdirs", &tdl)) {
|
if (formonitor) {
|
||||||
LOGERR("RclConfig::getTopdirs: no top directories in config or "
|
if (!getConfParam("monitordirs", &tdl)) {
|
||||||
"bad list format\n");
|
getConfParam("topdirs", &tdl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getConfParam("topdirs", &tdl);
|
||||||
|
}
|
||||||
|
if (tdl.empty()) {
|
||||||
|
LOGERR("RclConfig::getTopdirs: nothing to index: topdirs/monitordirs "
|
||||||
|
" are not set or have a bad list format\n");
|
||||||
return tdl;
|
return tdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
|
for (auto& dir : tdl) {
|
||||||
*it = path_tildexpand(*it);
|
dir = path_canon(path_tildexpand(dir));
|
||||||
*it = path_canon(*it);
|
|
||||||
}
|
}
|
||||||
return tdl;
|
return tdl;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,8 +182,11 @@ class RclConfig {
|
|||||||
|
|
||||||
/** Get list of top directories. This is needed from a number of places
|
/** Get list of top directories. This is needed from a number of places
|
||||||
* and needs some cleaning-up code. An empty list is always an error, no
|
* and needs some cleaning-up code. An empty list is always an error, no
|
||||||
* need for other status */
|
* need for other status
|
||||||
vector<string> getTopdirs() const;
|
* @param formonitor if set retrieve the list for real time monitoring
|
||||||
|
* (if the monitor list does not exist we return the normal one).
|
||||||
|
*/
|
||||||
|
vector<string> getTopdirs(bool formonitor = false) const;
|
||||||
|
|
||||||
string getConfdirPath(const char *varname, const char *dflt) const;
|
string getConfdirPath(const char *varname, const char *dflt) const;
|
||||||
string getCachedirPath(const char *varname, const char *dflt) const;
|
string getCachedirPath(const char *varname, const char *dflt) const;
|
||||||
|
|||||||
@ -161,8 +161,9 @@ void *rclMonRcvRun(void *q)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get top directories from config
|
// Get top directories from config. Special monitor sublist if
|
||||||
vector<string> tdl = lconfig.getTopdirs();
|
// set, else full list.
|
||||||
|
vector<string> tdl = lconfig.getTopdirs(true);
|
||||||
if (tdl.empty()) {
|
if (tdl.empty()) {
|
||||||
LOGERR("rclMonRcvRun:: top directory list (topdirs param.) not found "
|
LOGERR("rclMonRcvRun:: top directory list (topdirs param.) not found "
|
||||||
"in configuration or topdirs list parse error");
|
"in configuration or topdirs list parse error");
|
||||||
|
|||||||
@ -201,6 +201,18 @@ void rclIxIonice(const RclConfig *config)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setMyPriority(const RclConfig *config)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
||||||
|
LOGINFO("recollindex: can't setpriority(), errno " << errno << "\n");
|
||||||
|
}
|
||||||
|
// Try to ionice. This does not work on all platforms
|
||||||
|
rclIxIonice(config);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class MakeListWalkerCB : public FsTreeWalkerCB {
|
class MakeListWalkerCB : public FsTreeWalkerCB {
|
||||||
public:
|
public:
|
||||||
MakeListWalkerCB(list<string>& files, const vector<string>& selpats)
|
MakeListWalkerCB(list<string>& files, const vector<string>& selpats)
|
||||||
@ -316,10 +328,33 @@ static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
|
|||||||
vector<string> tdl;
|
vector<string> tdl;
|
||||||
if (!config->getConfParam("topdirs", &tdl)) {
|
if (!config->getConfParam("topdirs", &tdl)) {
|
||||||
cerr << "No 'topdirs' parameter in configuration\n";
|
cerr << "No 'topdirs' parameter in configuration\n";
|
||||||
LOGERR("recollindex:No 'topdirs' parameter in configuration\n");;
|
LOGERR("recollindex:No 'topdirs' parameter in configuration\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a restricted list for real-time monitoring exists check that
|
||||||
|
// all entries are descendants from a topdir
|
||||||
|
vector<string> mondirs;
|
||||||
|
if (config->getConfParam("monitordirs", &mondirs)) {
|
||||||
|
for (const auto& sub : mondirs) {
|
||||||
|
bool found{false};
|
||||||
|
for (const auto& top : tdl) {
|
||||||
|
if (path_isdesc(top, sub)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
string s("Real time monitoring directory entry " + sub +
|
||||||
|
" is not part of the topdirs tree\n");
|
||||||
|
cerr << s;
|
||||||
|
LOGERR(s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (vector<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
|
for (vector<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
|
||||||
*it = path_tildexpand(*it);
|
*it = path_tildexpand(*it);
|
||||||
if (!it->size() || !path_isabsolute(*it)) {
|
if (!it->size() || !path_isabsolute(*it)) {
|
||||||
@ -639,13 +674,7 @@ int main(int argc, char **argv)
|
|||||||
// Log something at LOGINFO to reset the trace file. Else at level
|
// Log something at LOGINFO to reset the trace file. Else at level
|
||||||
// 3 it's not even truncated if all docs are up to date.
|
// 3 it's not even truncated if all docs are up to date.
|
||||||
LOGINFO("recollindex: starting up\n");
|
LOGINFO("recollindex: starting up\n");
|
||||||
#ifndef _WIN32
|
setMyPriority(config);
|
||||||
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
|
||||||
LOGINFO("recollindex: can't setpriority(), errno " << errno << "\n");
|
|
||||||
}
|
|
||||||
// Try to ionice. This does not work on all platforms
|
|
||||||
rclIxIonice(config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (op_flags & OPT_r) {
|
if (op_flags & OPT_r) {
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
@ -732,15 +761,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
// Need to rewrite pid, it changed
|
// Need to rewrite pid, it changed
|
||||||
pidfile.write_pid();
|
pidfile.write_pid();
|
||||||
#ifndef _WIN32
|
|
||||||
// Not too sure if I have to redo the nice thing after daemon(),
|
// Not too sure if I have to redo the nice thing after daemon(),
|
||||||
// can't hurt anyway (easier than testing on all platforms...)
|
// can't hurt anyway (easier than testing on all platforms...)
|
||||||
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
setMyPriority(config);
|
||||||
LOGINFO("recollindex: can't setpriority(), errno " << errno<< "\n");
|
|
||||||
}
|
|
||||||
// Try to ionice. This does not work on all platforms
|
|
||||||
rclIxIonice(config);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (sleepsecs > 0) {
|
if (sleepsecs > 0) {
|
||||||
LOGDEB("recollindex: sleeping " << sleepsecs << "\n");
|
LOGDEB("recollindex: sleeping " << sleepsecs << "\n");
|
||||||
@ -753,6 +776,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(op_flags & OPT_n)) {
|
if (!(op_flags & OPT_n)) {
|
||||||
makeIndexerOrExit(config, inPlaceReset);
|
makeIndexerOrExit(config, inPlaceReset);
|
||||||
LOGDEB("Recollindex: initial indexing pass before monitoring\n");
|
LOGDEB("Recollindex: initial indexing pass before monitoring\n");
|
||||||
@ -776,10 +800,11 @@ int main(int argc, char **argv)
|
|||||||
// Note that -n will be inside the reexec when we come
|
// Note that -n will be inside the reexec when we come
|
||||||
// back, but the monitor will explicitely strip it before
|
// back, but the monitor will explicitely strip it before
|
||||||
// starting a config change exec to ensure that we do a
|
// starting a config change exec to ensure that we do a
|
||||||
// purging pass in this case.
|
// purging pass in this latter case (full restart).
|
||||||
o_reexec->reexec();
|
o_reexec->reexec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updater) {
|
if (updater) {
|
||||||
updater->status.phase = DbIxStatus::DBIXS_MONITOR;
|
updater->status.phase = DbIxStatus::DBIXS_MONITOR;
|
||||||
updater->status.fn.clear();
|
updater->status.fn.clear();
|
||||||
|
|||||||
@ -353,6 +353,29 @@ bool path_isroot(const string& path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool path_isdesc(const string& _top, const string& _sub)
|
||||||
|
{
|
||||||
|
string top = path_canon(_top);
|
||||||
|
string sub = path_canon(_sub);
|
||||||
|
path_catslash(top);
|
||||||
|
path_catslash(sub);
|
||||||
|
for (;;) {
|
||||||
|
if (sub == top) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
string::size_type l = sub.size();
|
||||||
|
sub = path_getfather(sub);
|
||||||
|
if (sub.size() == l || sub.size() < top.size()) {
|
||||||
|
// At root or sub shorter than top: done
|
||||||
|
if (sub == top) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool path_isabsolute(const string& path)
|
bool path_isabsolute(const string& path)
|
||||||
{
|
{
|
||||||
if (!path.empty() && (path[0] == '/'
|
if (!path.empty() && (path[0] == '/'
|
||||||
|
|||||||
@ -113,6 +113,10 @@ extern bool path_isabsolute(const std::string& s);
|
|||||||
/// Test if path is root (x:/). root is defined by root/.. == root
|
/// Test if path is root (x:/). root is defined by root/.. == root
|
||||||
extern bool path_isroot(const std::string& p);
|
extern bool path_isroot(const std::string& p);
|
||||||
|
|
||||||
|
/// Test if sub is a subdirectory of top. This is a textual test,
|
||||||
|
/// links not allowed
|
||||||
|
extern bool path_isdesc(const std::string& top, const std::string& sub);
|
||||||
|
|
||||||
/// Turn absolute path into file:// url
|
/// Turn absolute path into file:// url
|
||||||
extern std::string path_pathtofileurl(const std::string& path);
|
extern std::string path_pathtofileurl(const std::string& path);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user