add skippedPaths and daemSkippedPaths config variables

This commit is contained in:
dockes 2007-02-02 10:12:58 +00:00
parent 68b25b750c
commit fde963eb2e
5 changed files with 72 additions and 32 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.40 2006-12-20 13:12:49 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.41 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -436,7 +436,7 @@ string RclConfig::getDbDir()
} }
} }
LOGDEB1(("RclConfig::getDbDir: dbdir: [%s]\n", dbdir.c_str())); LOGDEB1(("RclConfig::getDbDir: dbdir: [%s]\n", dbdir.c_str()));
return dbdir; return path_canon(dbdir);
} }
list<string> RclConfig::getSkippedNames() list<string> RclConfig::getSkippedNames()
@ -446,16 +446,46 @@ list<string> RclConfig::getSkippedNames()
if (getConfParam("skippedNames", skipped)) { if (getConfParam("skippedNames", skipped)) {
stringToStrings(skipped, skpl); stringToStrings(skipped, skpl);
} }
// If current keydir is dbdir's ancestor, add dbdir name to skipped return skpl;
// This is mainly for the real-time monitor that will otherwise go }
// into a loop
// We'd prefer to do it for the direct ancestor only, but getSkippedNames() list<string> RclConfig::getSkippedPaths()
// is only called for the topdirs, so this doesn't work {
string kd = path_canon(getKeyDir()); list<string> skpl;
string dbd = path_canon(getDbDir()); string skipped;
if (dbd.find(kd) == 0) { if (getConfParam("skippedPaths", skipped)) {
skpl.push_back(path_getsimple(dbd)); stringToStrings(skipped, skpl);
} }
// Always add the dbdir and confdir to the skipped paths
skpl.push_back(getDbDir());
skpl.push_back(getConfDir());
for (list<string>::iterator it = skpl.begin(); it != skpl.end(); it++) {
*it = path_tildexpand(*it);
*it = path_canon(*it);
}
skpl.sort();
skpl.unique();
return skpl;
}
list<string> RclConfig::getDaemSkippedPaths()
{
list<string> skpl = getSkippedPaths();
list<string> dskpl;
string skipped;
if (getConfParam("daemSkippedPaths", skipped)) {
stringToStrings(skipped, dskpl);
}
for (list<string>::iterator it = dskpl.begin(); it != dskpl.end(); it++) {
*it = path_tildexpand(*it);
*it = path_canon(*it);
}
dskpl.sort();
skpl.merge(dskpl);
skpl.unique();
return skpl; return skpl;
} }

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _RCLCONFIG_H_INCLUDED_ #ifndef _RCLCONFIG_H_INCLUDED_
#define _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_
/* @(#$Id: rclconfig.h,v 1.30 2006-12-20 13:12:49 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: rclconfig.h,v 1.31 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes */
#include <list> #include <list>
#include <string> #include <string>
@ -82,6 +82,13 @@ class RclConfig {
/** Get list of skipped names for current keydir */ /** Get list of skipped names for current keydir */
list<string> getSkippedNames(); list<string> getSkippedNames();
/** Get list of skipped paths patterns. Doesn't depend on the keydir */
list<string> getSkippedPaths();
/** Get list of skipped paths patterns, daemon version (may add some)
Doesn't depend on the keydir */
list<string> getDaemSkippedPaths();
/** /**
* Check if file name should be ignored because of suffix * Check if file name should be ignored because of suffix
* *

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.50 2006-12-21 09:22:31 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: indexer.cpp,v 1.51 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -82,10 +82,7 @@ bool DbIndexer::indexDb(bool resetbefore, list<string> *topdirs)
m_updater->status.dbtotdocs = m_db.docCnt(); m_updater->status.dbtotdocs = m_db.docCnt();
} }
// Always add dbdir and confdir to skipped paths. m_walker.setSkippedPaths(m_config->getSkippedPaths());
m_walker.setSkippedPaths(list<string>());
m_walker.addSkippedPath(m_config->getConfDir());
m_walker.addSkippedPath(m_dbdir);
for (list<string>::const_iterator it = topdirs->begin(); for (list<string>::const_iterator it = topdirs->begin();
it != topdirs->end(); it++) { it != topdirs->end(); it++) {

View File

@ -1,7 +1,7 @@
#include "autoconfig.h" #include "autoconfig.h"
#ifdef RCL_MONITOR #ifdef RCL_MONITOR
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.9 2006-12-21 09:22:31 dockes Exp $ (C) 2006 J.F.Dockes"; static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.10 2007-02-02 10:12:58 dockes Exp $ (C) 2006 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -128,13 +128,18 @@ void *rclMonRcvRun(void *q)
// Walk the directory trees to add watches // Walk the directory trees to add watches
FsTreeWalker walker; FsTreeWalker walker;
walker.addSkippedPath(queue->getConfig()->getConfDir()); walker.setSkippedPaths(queue->getConfig()->getDaemSkippedPaths());
WalkCB walkcb(queue->getConfig(), mon, queue); WalkCB walkcb(queue->getConfig(), mon, queue);
for (list<string>::iterator it = tdl.begin(); it != tdl.end(); it++) { for (list<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
queue->getConfig()->setKeyDir(*it); queue->getConfig()->setKeyDir(*it);
// Adjust the skipped names according to config, and add the dbdir to // Adjust the skipped names according to config
// skipped paths
walker.setSkippedNames(queue->getConfig()->getSkippedNames()); walker.setSkippedNames(queue->getConfig()->getSkippedNames());
// Add the dbdir to skipped paths. Note that adding the dbdir
// is probably not useful as we'll probably never have
// multiple dbs per config file, and the global dbdir is
// included by
// config->getSkippedPaths(). Still, better to be safe here as
// config->including dbdir in the walk will get us into a loop
walker.addSkippedPath(queue->getConfig()->getDbDir()); walker.addSkippedPath(queue->getConfig()->getDbDir());
LOGDEB(("rclMonRcvRun: walking %s\n", it->c_str())); LOGDEB(("rclMonRcvRun: walking %s\n", it->c_str()));
walker.walk(*it, walkcb); walker.walk(*it, walkcb);

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.10 2006-12-21 09:22:31 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.11 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -90,11 +90,12 @@ bool FsTreeWalker::setSkippedNames(const list<string> &patterns)
return true; return true;
} }
bool FsTreeWalker::addSkippedPath(const string& path) bool FsTreeWalker::addSkippedPath(const string& ipath)
{ {
string path = path_canon(ipath);
if (find(data->skippedPaths.begin(), if (find(data->skippedPaths.begin(),
data->skippedPaths.end(), path) == data->skippedPaths.end()) data->skippedPaths.end(), path) == data->skippedPaths.end())
data->skippedPaths.push_back(path_canon(path)); data->skippedPaths.push_back(path);
return true; return true;
} }
bool FsTreeWalker::setSkippedPaths(const list<string> &paths) bool FsTreeWalker::setSkippedPaths(const list<string> &paths)
@ -181,16 +182,16 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
data->logsyserr("stat", fn); data->logsyserr("stat", fn);
continue; continue;
} }
if (S_ISDIR(st.st_mode)) { if (!data->skippedPaths.empty()) {
if (!data->skippedPaths.empty()) { list<string>::const_iterator it;
list<string>::const_iterator it; for (it = data->skippedPaths.begin();
for (it = data->skippedPaths.begin(); it != data->skippedPaths.end(); it++) {
it != data->skippedPaths.end(); it++) { if (fnmatch(it->c_str(), fn.c_str(), FNM_PATHNAME) == 0)
if (fn == *it) goto skip;
goto skip;
}
} }
}
if (S_ISDIR(st.st_mode)) {
if (data->options & FtwNoRecurse) { if (data->options & FtwNoRecurse) {
status = cb.processone(fn, &st, FtwDirEnter); status = cb.processone(fn, &st, FtwDirEnter);
} else { } else {