summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugin.py
diff options
context:
space:
mode:
authorMike McCallister <mike@mccllstr.com>2011-07-29 11:56:48 -0500
committerMike McCallister <mike@mccllstr.com>2011-07-29 11:56:48 -0500
commit7fd2e4c470041c353c2632fd0a838c43cb3c4a99 (patch)
treeee3aaaf3184213672d7fd3e129bddc4ca93504be /src/lib/Server/Plugin.py
parente2dc5f5a5fbc992c39d36693de552c275fef8f47 (diff)
downloadbcfg2-7fd2e4c470041c353c2632fd0a838c43cb3c4a99.tar.gz
bcfg2-7fd2e4c470041c353c2632fd0a838c43cb3c4a99.tar.bz2
bcfg2-7fd2e4c470041c353c2632fd0a838c43cb3c4a99.zip
Fix error that occurs when deleting and re-creating the same directory.
FileMonitor never forgets about directories you've asked it to watch, so we should never remove them from self.handles. Otherwise, once deleted and readded, events will arrive with a requestID we don't have a handle for.
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r--src/lib/Server/Plugin.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index a79fac0e1..3dc7bc783 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -387,7 +387,7 @@ class DirectoryBacked(object):
"""
object.__init__(self)
- self.data = data
+ self.data = os.path.normpath(data)
self.fam = fam
# self.entries contains information about the files monitored
@@ -441,17 +441,18 @@ class DirectoryBacked(object):
"""
action = event.code2str()
- # Exclude events for actions and filesystem paths we don't
- # care about
+ # Clean up the absolute path names passed in
+ event.filename = os.path.normpath(event.filename)
+ if event.filename.startswith(self.data):
+ event.filename = event.filename[len(self.data)+1:]
+
+ # Exclude events for actions we don't care about
if action == 'endExist':
return
- elif os.path.isabs(event.filename[0]):
- # After AddDirectoryMonitor calls, we receive an 'exists'
- # event with the just-added directory and its absolute
- # path name. Ignore these.
- return
- elif event.filename == '':
- logger.warning("Got event for blank filename")
+
+ if event.requestID not in self.handles:
+ logger.warn("Got %s event with unknown handle (%s) for %s"
+ % (action, event.requestID, abspath))
return
# Calculate the absolute and relative paths this event refers to
@@ -463,9 +464,11 @@ class DirectoryBacked(object):
for key in self.entries.keys():
if key.startswith(relpath):
del self.entries[key]
- for handle in self.handles.keys():
- if self.handles[handle].startswith(relpath):
- del self.handles[handle]
+ # We remove values from self.entries, but not
+ # self.handles, because the FileMonitor doesn't stop
+ # watching a directory just because it gets deleted. If it
+ # is recreated, we will start getting notifications for it
+ # again without having to add a new monitor.
elif posixpath.isdir(abspath):
# Deal with events for directories
if action in ['exists', 'created']: