Commit 1fabf762 by rfkelly0

fix race condition in watch_inotify

parent c56bc5e2
...@@ -47,7 +47,6 @@ class OSFSWatchMixin(WatchableFSMixin): ...@@ -47,7 +47,6 @@ class OSFSWatchMixin(WatchableFSMixin):
OSFSWatchMixin.__watch_thread = None OSFSWatchMixin.__watch_thread = None
finally: finally:
self.__watch_lock.release() self.__watch_lock.release()
def add_watcher(self,callback,path="/",events=None,recursive=True): def add_watcher(self,callback,path="/",events=None,recursive=True):
super_add_watcher = super(OSFSWatchMixin,self).add_watcher super_add_watcher = super(OSFSWatchMixin,self).add_watcher
...@@ -203,7 +202,7 @@ class SharedThreadedNotifier(threading.Thread): ...@@ -203,7 +202,7 @@ class SharedThreadedNotifier(threading.Thread):
def __init__(self): def __init__(self):
super(SharedThreadedNotifier,self).__init__() super(SharedThreadedNotifier,self).__init__()
self.daemon = True self.daemon = True
self.running = False self.running = True
self._pipe_r, self._pipe_w = os.pipe() self._pipe_r, self._pipe_w = os.pipe()
self._poller = select.poll() self._poller = select.poll()
self._poller.register(self._pipe_r,select.POLLIN) self._poller.register(self._pipe_r,select.POLLIN)
...@@ -231,7 +230,6 @@ class SharedThreadedNotifier(threading.Thread): ...@@ -231,7 +230,6 @@ class SharedThreadedNotifier(threading.Thread):
_select_error = select.error _select_error = select.error
_select_POLLIN = select.POLLIN _select_POLLIN = select.POLLIN
# Loop until stopped, dispatching to individual notifiers. # Loop until stopped, dispatching to individual notifiers.
self.running = True
while self.running: while self.running:
try: try:
ready_fds = self._poller.poll() ready_fds = self._poller.poll()
......
...@@ -143,12 +143,18 @@ class TestXAttr_TempFS(unittest.TestCase,FSTestCases,XAttrTestCases): ...@@ -143,12 +143,18 @@ class TestXAttr_TempFS(unittest.TestCase,FSTestCases,XAttrTestCases):
self.fs = ensure_xattrs(fs) self.fs = ensure_xattrs(fs)
def tearDown(self): def tearDown(self):
td = self.fs._temp_dir try:
td = self.fs._temp_dir
except AttributeError:
td = self.fs.wrapped_fs._temp_dir
self.fs.close() self.fs.close()
self.assert_(not os.path.exists(td)) self.assert_(not os.path.exists(td))
def check(self, p): def check(self, p):
td = self.fs._temp_dir try:
td = self.fs._temp_dir
except AttributeError:
td = self.fs.wrapped_fs._temp_dir
return os.path.exists(os.path.join(td, relpath(p))) return os.path.exists(os.path.join(td, relpath(p)))
......
...@@ -314,9 +314,15 @@ class WatchableFS(WatchableFSMixin,WrapFS): ...@@ -314,9 +314,15 @@ class WatchableFS(WatchableFSMixin,WrapFS):
raise DirectoryNotEmptyError(path) raise DirectoryNotEmptyError(path)
else: else:
for nm in self.listdir(path,dirs_only=True): for nm in self.listdir(path,dirs_only=True):
self.removedir(pathjoin(path,nm),force=True) try:
self.removedir(pathjoin(path,nm),force=True)
except ResourceNotFoundError:
pass
for nm in self.listdir(path,files_only=True): for nm in self.listdir(path,files_only=True):
self.remove(pathjoin(path,nm)) try:
self.remove(pathjoin(path,nm))
except ResourceNotFoundError:
pass
super(WatchableFS,self).removedir(path) super(WatchableFS,self).removedir(path)
self.notify_watchers(REMOVED,path) self.notify_watchers(REMOVED,path)
if recursive: if recursive:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment