gorakhargosh/watchdog — pull request #140 by jonboulle (2012-12-14 02:02:18+00:00)
Title: Fix handling of moving path outside monitored directory into monitored directory

When moving a non-monitored recursive directory into the monitored path, the DirMovedEvent throws an exception when trying to generate its sub_moved_events - because there's no check on the value of the src_path (always None when the source directory is outside our monitored directory)

This patch addresses this in the least-invasive manner, by simply setting the source path to None on all the generated sub events as it is for the parent event.

Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
File "/lib/python2.6/site-packages/watchdog/observers/api.py", line 191, in run
self.queue_events(self.timeout)
File "/lib/python2.6/site-packages/watchdog/observers/inotify.py", line 772, in queue_events
for sub_event in event.sub_moved_events():
File "/lib/python2.6/site-packages/watchdog/events.py", line 327, in sub_moved_events
_walker=_walker))
File "/lib/python2.6/site-packages/watchdog/events.py", line 610, in _generate_sub_moved_events_for
src_dir_path = absolute_path(src_dir_path)
File "/lib/python2.6/site-packages/pathtools/path.py", line 183, in absolute_path
return os.path.abspath(os.path.normpath(path))
File "/usr/lib64/python2.6/posixpath.py", line 314, in normpath
initial_slashes = path.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'