summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike McCallister <mike@mccllstr.com>2011-08-05 13:15:44 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-08-09 15:13:53 -0500
commita50d2a2c23415f5ce2f6941e9ae60532bf34b5be (patch)
treedd7d0d0f209b1012b6300e4a35149748859a45e6
parentb567471a5214475d048ba77c584645a7b8b9e571 (diff)
downloadbcfg2-a50d2a2c23415f5ce2f6941e9ae60532bf34b5be.tar.gz
bcfg2-a50d2a2c23415f5ce2f6941e9ae60532bf34b5be.tar.bz2
bcfg2-a50d2a2c23415f5ce2f6941e9ae60532bf34b5be.zip
Be a little more conservative in handling "changed" events.
Previously, if we got a "changed" event for a path we weren't monitoring, we would log a warning and ignore it. Now, we log the warning, but treat it like a "created" event so we know about the file/directory going forward. This situation shouldn't occur, but this new logic will handle it a little better. (cherry picked from commit 29701f299632ea343d7b58af4d3b7a143ced0078)
-rw-r--r--src/lib/Server/Plugin.py61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 3a306756a..2e7bef5f5 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -5,6 +5,7 @@ import copy
import logging
import lxml.etree
import os
+import os.path
import pickle
import posixpath
import re
@@ -427,6 +428,18 @@ class DirectoryBacked(object):
reqid = self.fam.AddMonitor(dirpathname, self)
self.handles[reqid] = relative
+ def add_entry(self, relative, event):
+ """Add a new file to our structures for monitoring.
+
+ :param relative: Path name to monitor. This must be relative
+ to the plugin's directory.
+ :param event: File Monitor event that caused this entry to be
+ added.
+ """
+ self.entries[relative] = self.__child__(os.path.join(self.data,
+ relative))
+ self.entries[relative].HandleEvent(event)
+
def HandleEvent(self, event):
"""Handle FAM/Gamin events.
@@ -473,19 +486,29 @@ class DirectoryBacked(object):
# Deal with events for directories
if action in ['exists', 'created']:
self.add_directory_monitor(relpath)
- elif action == 'changed' and relpath in self.entries:
- # Ownerships, permissions or timestamps changed on the
- # directory. None of these should affect the contents
- # of the files, though it could change our ability to
- # access them.
- #
- # It seems like the right thing to do is to cancel
- # monitoring the directory and then begin monitoring
- # it again. But the current FileMonitor class doesn't
- # support canceling, so at least let the user know
- # that a restart might be a good idea.
- logger.warn("Directory properties for %s changed, please " +
- " consider restarting the server" % (abspath))
+ elif action == 'changed':
+ if relpath in self.entries:
+ # Ownerships, permissions or timestamps changed on
+ # the directory. None of these should affect the
+ # contents of the files, though it could change
+ # our ability to access them.
+ #
+ # It seems like the right thing to do is to cancel
+ # monitoring the directory and then begin
+ # monitoring it again. But the current FileMonitor
+ # class doesn't support canceling, so at least let
+ # the user know that a restart might be a good
+ # idea.
+ logger.warn("Directory properties for %s changed, please " +
+ " consider restarting the server" % (abspath))
+ else:
+ # Got a "changed" event for a directory that we
+ # didn't know about. Go ahead and treat it like a
+ # "created" event, but log a warning, because this
+ # is unexpected.
+ logger.warn("Got %s event for unexpected dir %s" % (action,
+ abspath))
+ self.add_directory_monitor(relpath)
else:
logger.warn("Got unknown dir event %s %s %s" % (event.requestID,
event.code2str(),
@@ -500,14 +523,18 @@ class DirectoryBacked(object):
return
if not self.patterns.match(event.filename):
return
- self.entries[relpath] = self.__child__('%s/%s' % (self.data,
- relpath))
- self.entries[relpath].HandleEvent(event)
+ self.add_entry(relpath, event)
elif action == 'changed':
if relpath in self.entries:
self.entries[relpath].HandleEvent(event)
else:
- logger.warn("Got %s event for unexpected path %s" % (action, abspath))
+ # Got a "changed" event for a file that we didn't
+ # know about. Go ahead and treat it like a
+ # "created" event, but log a warning, because this
+ # is unexpected.
+ logger.warn("Got %s event for unexpected file %s" % (action,
+ abspath))
+ self.add_entry(relpath, event)
else:
logger.warn("Got unknown file event %s %s %s" % (event.requestID,
event.code2str(),