Skip to content

Commit

Permalink
BF: pyinotify backend should also handle IN_MOVED_TO events
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Apr 29, 2013
1 parent 2a0ce5d commit f215660
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/filterpyinotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, jail):
def callback(self, event, origin=''):
logSys.debug("%sCallback for Event: %s", origin, event)
path = event.pathname
if event.mask & pyinotify.IN_CREATE:
if event.mask & ( pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO ):
# skip directories altogether
if event.mask & pyinotify.IN_ISDIR:
logSys.debug("Ignoring creation of directory %s", path)
Expand Down Expand Up @@ -130,7 +130,7 @@ def _addLogPath(self, path):
if not (path_dir in self.__watches):
# we need to watch also the directory for IN_CREATE
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)

self._addFileWatcher(path)
Expand Down
34 changes: 34 additions & 0 deletions testcases/filtertestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,40 @@ def test_move_file(self):
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):
# to make sure that watching whole directory does not effect
_copy_lines_between_files(GetFailures.FILENAME_01, self.name, n=100)
Expand Down

0 comments on commit f215660

Please sign in to comment.