monitor: dont add watch on created dir if in skippedXXX

This commit is contained in:
dockes 2007-07-12 10:53:07 +00:00
parent acc251054e
commit 16bca7840a
3 changed files with 38 additions and 20 deletions

View File

@ -1,7 +1,7 @@
#include "autoconfig.h"
#ifdef RCL_MONITOR
#ifndef lint
static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.11 2007-05-21 13:30:21 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.12 2007-07-12 10:53:07 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -158,7 +158,12 @@ void *rclMonRcvRun(void *q)
// timeout so that an intr will be detected
if (mon->getEvent(ev, 2)) {
if (ev.m_etyp == RclMonEvent::RCLEVT_DIRCREATE) {
mon->addWatch(ev.m_path, true);
// Add watch after checking that this doesn't match
// ignored files or paths
string name = path_getsimple(ev.m_path);
if (!walker.inSkippedNames(name) &&
!walker.inSkippedPaths(ev.m_path))
mon->addWatch(ev.m_path, true);
}
if (ev.m_etyp != RclMonEvent::RCLEVT_NONE)
queue->pushEvent(ev);

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.11 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.12 2007-07-12 10:53:07 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -89,6 +89,17 @@ bool FsTreeWalker::setSkippedNames(const list<string> &patterns)
data->skippedNames.unique();
return true;
}
bool FsTreeWalker::inSkippedNames(const string& name)
{
list<string>::const_iterator it;
for (it = data->skippedNames.begin();
it != data->skippedNames.end(); it++) {
if (fnmatch(it->c_str(), name.c_str(), 0) == 0) {
return true;
}
}
return false;
}
bool FsTreeWalker::addSkippedPath(const string& ipath)
{
@ -108,6 +119,16 @@ bool FsTreeWalker::setSkippedPaths(const list<string> &paths)
data->skippedPaths.unique();
return true;
}
bool FsTreeWalker::inSkippedPaths(const string& path)
{
list<string>::const_iterator it;
for (it = data->skippedPaths.begin();
it != data->skippedPaths.end(); it++) {
if (fnmatch(it->c_str(), path.c_str(), FNM_PATHNAME) == 0)
return true;
}
return false;
}
FsTreeWalker::Status FsTreeWalker::walk(const string &top,
FsTreeWalkerCB& cb)
@ -156,20 +177,14 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
struct dirent *ent;
while ((ent = readdir(d)) != 0) {
// We do process hidden files for now, only skip . and ..
// Skip . and ..
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
// Skipped file names match ?
if (!data->skippedNames.empty()) {
list<string>::const_iterator it;
for (it = data->skippedNames.begin();
it != data->skippedNames.end(); it++) {
if (fnmatch(it->c_str(), ent->d_name, 0) == 0) {
//fprintf(stderr,
//"Skipping [%s] because of pattern match\n", ent->d_name);
goto skip;
}
}
if (inSkippedNames(ent->d_name))
goto skip;
}
{
@ -183,12 +198,8 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
continue;
}
if (!data->skippedPaths.empty()) {
list<string>::const_iterator it;
for (it = data->skippedPaths.begin();
it != data->skippedPaths.end(); it++) {
if (fnmatch(it->c_str(), fn.c_str(), FNM_PATHNAME) == 0)
goto skip;
}
if (inSkippedPaths(fn))
goto skip;
}
if (S_ISDIR(st.st_mode)) {

View File

@ -16,7 +16,7 @@
*/
#ifndef _FSTREEWALK_H_INCLUDED_
#define _FSTREEWALK_H_INCLUDED_
/* @(#$Id: fstreewalk.h,v 1.6 2006-12-21 08:22:35 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: fstreewalk.h,v 1.7 2007-07-12 10:53:07 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@ -71,6 +71,8 @@ class FsTreeWalker {
/** Set the ignored paths list */
bool setSkippedPaths(const list<string> &pathlist);
bool inSkippedPaths(const string& path);
bool inSkippedNames(const string& name);
private:
Status iwalk(const string &dir, FsTreeWalkerCB& cb);
class Internal;