BF: pyinotify backend should also handle IN_MOVED_TO events

pull/199/head
Yaroslav Halchenko 2013-04-29 13:54:14 -04:00
parent 2a0ce5da09
commit f21566049c
2 changed files with 36 additions and 2 deletions

View File

@ -66,7 +66,7 @@ class FilterPyinotify(FileFilter):
def callback(self, event, origin=''): def callback(self, event, origin=''):
logSys.debug("%sCallback for Event: %s", origin, event) logSys.debug("%sCallback for Event: %s", origin, event)
path = event.pathname path = event.pathname
if event.mask & pyinotify.IN_CREATE: if event.mask & ( pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO ):
# skip directories altogether # skip directories altogether
if event.mask & pyinotify.IN_ISDIR: if event.mask & pyinotify.IN_ISDIR:
logSys.debug("Ignoring creation of directory %s", path) logSys.debug("Ignoring creation of directory %s", path)
@ -130,7 +130,7 @@ class FilterPyinotify(FileFilter):
if not (path_dir in self.__watches): if not (path_dir in self.__watches):
# we need to watch also the directory for IN_CREATE # we need to watch also the directory for IN_CREATE
self.__watches.update( self.__watches.update(
self.__monitor.add_watch(path_dir, pyinotify.IN_CREATE)) self.__monitor.add_watch(path_dir, pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO))
logSys.debug("Added monitor for the parent directory %s", path_dir) logSys.debug("Added monitor for the parent directory %s", path_dir)
self._addFileWatcher(path) self._addFileWatcher(path)

View File

@ -475,6 +475,40 @@ def get_monitor_failures_testcase(Filter_):
self.assertEqual(self.filter.failManager.getFailTotal(), 6) self.assertEqual(self.filter.failManager.getFailTotal(), 6)
def _test_move_into_file(self, interim_kill=False):
# if we move a new file into the location of an old (monitored) file
self.file1 = _copy_lines_between_files(GetFailures.FILENAME_01, self.name,
n=100)
# make sure that it is monitored first
self.assert_correct_last_attempt(GetFailures.FAILURES_01)
self.assertEqual(self.filter.failManager.getFailTotal(), 3)
if interim_kill:
_killfile(None, self.name)
time.sleep(0.2) # let them know
# now create a new one to override old one
self.file = _copy_lines_between_files(GetFailures.FILENAME_01,
self.name + '.new', n=100)
os.rename(self.name + '.new', self.name)
self.assert_correct_last_attempt(GetFailures.FAILURES_01)
self.assertEqual(self.filter.failManager.getFailTotal(), 6)
# and to make sure that it now monitored for changes
_copy_lines_between_files(GetFailures.FILENAME_01, self.name, n=100)
self.assert_correct_last_attempt(GetFailures.FAILURES_01)
self.assertEqual(self.filter.failManager.getFailTotal(), 9)
def test_move_into_file(self):
self._test_move_into_file(interim_kill=False)
def test_move_into_file_after_removed(self):
# exactly as above test + remove file explicitly
# to test against possible drop-out of the file from monitoring
self._test_move_into_file(interim_kill=True)
def test_new_bogus_file(self): def test_new_bogus_file(self):
# to make sure that watching whole directory does not effect # to make sure that watching whole directory does not effect
_copy_lines_between_files(GetFailures.FILENAME_01, self.name, n=100) _copy_lines_between_files(GetFailures.FILENAME_01, self.name, n=100)