From 16bca7840a01ebbb3cbe0e6d2ec8fdf8695edbdb Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 12 Jul 2007 10:53:07 +0000 Subject: [PATCH] monitor: dont add watch on created dir if in skippedXXX --- src/index/rclmonrcv.cpp | 9 ++++++-- src/utils/fstreewalk.cpp | 45 +++++++++++++++++++++++++--------------- src/utils/fstreewalk.h | 4 +++- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/index/rclmonrcv.cpp b/src/index/rclmonrcv.cpp index be259608..e5b938d6 100644 --- a/src/index/rclmonrcv.cpp +++ b/src/index/rclmonrcv.cpp @@ -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); diff --git a/src/utils/fstreewalk.cpp b/src/utils/fstreewalk.cpp index f8cdd860..79cff453 100644 --- a/src/utils/fstreewalk.cpp +++ b/src/utils/fstreewalk.cpp @@ -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 &patterns) data->skippedNames.unique(); return true; } +bool FsTreeWalker::inSkippedNames(const string& name) +{ + list::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 &paths) data->skippedPaths.unique(); return true; } +bool FsTreeWalker::inSkippedPaths(const string& path) +{ + list::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::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::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)) { diff --git a/src/utils/fstreewalk.h b/src/utils/fstreewalk.h index d0f467be..8c0d38ad 100644 --- a/src/utils/fstreewalk.h +++ b/src/utils/fstreewalk.h @@ -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 #include @@ -71,6 +71,8 @@ class FsTreeWalker { /** Set the ignored paths list */ bool setSkippedPaths(const list &pathlist); + bool inSkippedPaths(const string& path); + bool inSkippedNames(const string& name); private: Status iwalk(const string &dir, FsTreeWalkerCB& cb); class Internal;