Commit e91c3e81 by rfkelly0

fix some corner cases in osfs/watch_win32.py

parent d7759718
...@@ -15,7 +15,7 @@ implementations of this interface such as: ...@@ -15,7 +15,7 @@ implementations of this interface such as:
""" """
__version__ = "0.3.0" __version__ = "0.4.0a1"
__author__ = "Will McGugan (will@willmcgugan.com)" __author__ = "Will McGugan (will@willmcgugan.com)"
# 'base' imports * from 'path' and 'errors', so their # 'base' imports * from 'path' and 'errors', so their
......
...@@ -424,6 +424,7 @@ class FS(object): ...@@ -424,6 +424,7 @@ class FS(object):
""" """
raise UnsupportedError("rename resource") raise UnsupportedError("rename resource")
@convert_os_errors
def settimes(self, path, accessed_time=None, modified_time=None): def settimes(self, path, accessed_time=None, modified_time=None):
"""Set the accessed time and modified time of a file """Set the accessed time and modified time of a file
......
...@@ -233,6 +233,8 @@ def convert_os_errors(func): ...@@ -233,6 +233,8 @@ def convert_os_errors(func):
raise StorageSpaceError(opname,details=e),None,tb raise StorageSpaceError(opname,details=e),None,tb
if e.errno == errno.EPERM: if e.errno == errno.EPERM:
raise PermissionDeniedError(opname,details=e),None,tb raise PermissionDeniedError(opname,details=e),None,tb
if e.errno == errno.ENOSYS:
raise UnsupportedError(opname,details=e),None,tb
if e.errno == errno.EACCES: if e.errno == errno.EACCES:
if sys.platform == "win32": if sys.platform == "win32":
if e.args[0] and e.args[0] == 32: if e.args[0] and e.args[0] == 32:
......
""" """
fs.osfs.watch_win32 fs.osfs.watch_win32
============= ===================
Change watcher support for OSFS, using ReadDirectoryChangesW on win32. Change watcher support for OSFS, using ReadDirectoryChangesW on win32.
...@@ -359,7 +359,11 @@ class WatchThread(threading.Thread): ...@@ -359,7 +359,11 @@ class WatchThread(threading.Thread):
traceback.print_exc() traceback.print_exc()
else: else:
if iocpkey.value > 1: if iocpkey.value > 1:
try:
w = self.watched_directories[iocpkey.value] w = self.watched_directories[iocpkey.value]
except KeyError:
pass
else:
w.complete(nbytes.value) w.complete(nbytes.value)
w.post() w.post()
elif not self.closed: elif not self.closed:
...@@ -405,11 +409,13 @@ class OSFSWatchMixin(WatchableFSMixin): ...@@ -405,11 +409,13 @@ class OSFSWatchMixin(WatchableFSMixin):
try: try:
path = self.unsyspath(path) path = self.unsyspath(path)
except ValueError: except ValueError:
raise pass
else: else:
if event_class in (MOVED_SRC,MOVED_DST) and args and args[0]:
args = (self.unsyspath(args[0]),) + args[1:]
event = event_class(self,path,*args,**kwds) event = event_class(self,path,*args,**kwds)
w.handle_event(event) w.handle_event(event)
w._watch_obj = wt.add_watcher(handle_event,syspath,w.events,w.recursive) w._watch_objs = wt.add_watcher(handle_event,syspath,w.events,w.recursive)
return w return w
@convert_os_errors @convert_os_errors
...@@ -420,7 +426,8 @@ class OSFSWatchMixin(WatchableFSMixin): ...@@ -420,7 +426,8 @@ class OSFSWatchMixin(WatchableFSMixin):
else: else:
watchers = self._find_watchers(watcher_or_callback) watchers = self._find_watchers(watcher_or_callback)
for watcher in watchers: for watcher in watchers:
wt.del_watcher(watcher._watch_obj) for wobj in watcher._watch_objs:
wt.del_watcher(wobj)
super(OSFSWatchMixin,self).del_watcher(watcher) super(OSFSWatchMixin,self).del_watcher(watcher)
if not wt.watched_directories: if not wt.watched_directories:
self.__shutdown_watch_thread() self.__shutdown_watch_thread()
...@@ -451,6 +458,8 @@ class OSFSWatchMixin(WatchableFSMixin): ...@@ -451,6 +458,8 @@ class OSFSWatchMixin(WatchableFSMixin):
OSFSWatchMixin.__watch_thread.close() OSFSWatchMixin.__watch_thread.close()
except EnvironmentError: except EnvironmentError:
pass pass
else:
OSFSWatchMixin.__watch_thread.join()
OSFSWatchMixin.__watch_thread = None OSFSWatchMixin.__watch_thread = None
finally: finally:
self.__watch_lock.release() self.__watch_lock.release()
......
...@@ -47,6 +47,7 @@ class TempFS(OSFS): ...@@ -47,6 +47,7 @@ class TempFS(OSFS):
Note that once this method has been called, the FS object may Note that once this method has been called, the FS object may
no longer be used. no longer be used.
""" """
super(TempFS,self).close()
# Depending on how resources are freed by the OS, there could # Depending on how resources are freed by the OS, there could
# be some transient errors when freeing a TempFS soon after it # be some transient errors when freeing a TempFS soon after it
# was used. If they occur, do a small sleep and try again. # was used. If they occur, do a small sleep and try again.
......
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