From 4c130634980f2acc3b9d7352529d9f5a388435c1 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Sat, 31 Dec 2011 03:33:58 -0500 Subject: [PATCH] Added addLogPath and delLogPath functionality (adds/removes paths from the WatchManager) --- server/filterpyinotify.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/filterpyinotify.py b/server/filterpyinotify.py index 11c5f911..ec6f53da 100644 --- a/server/filterpyinotify.py +++ b/server/filterpyinotify.py @@ -54,6 +54,7 @@ class FilterPyinotify(FileFilter): # Pyinotify watch manager self.monitor = pyinotify.WatchManager() logSys.debug("Created FilterPyinotify") + self.__watches = dict() def callback(self, path): @@ -76,7 +77,8 @@ class FilterPyinotify(FileFilter): if self.containsLogPath(path): logSys.error(path + " already exists") else: - self.monitor.add_watch(path, pyinotify.IN_MODIFY) + wd = self.monitor.add_watch(path, pyinotify.IN_MODIFY) + self.__watches.update(wd) FileFilter.addLogPath(self, path, tail) logSys.info("Added logfile = %s" % path) @@ -89,8 +91,14 @@ class FilterPyinotify(FileFilter): if not self.containsLogPath(path): logSys.error(path + " is not monitored") else: - FileFilter.delLogPath(self, path) - logSys.info("Removed logfile = %s" % path) + wdInt = self.__watches[path] + wd = self.monitor.rm_watch(wdInt) + if wd[wdInt]: + del self.__watches[path] + FileFilter.delLogPath(self, path) + logSys.info("Removed logfile = %s" % path) + else: + logSys.error("Failed to remove watch on path: %s", path) ## # Main loop.