summaryrefslogtreecommitdiff
path: root/fs/expose/dokan
diff options
context:
space:
mode:
authorrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2010-10-01 02:16:34 +0000
committerrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2010-10-01 02:16:34 +0000
commit204c1602b292ced5653005d84d107b7899989e55 (patch)
tree47083eb84c6bfca576a4c71ee0328e6a703282f0 /fs/expose/dokan
parent3e4592708f6e08d6fa52a1b8a29cbe78c45038d5 (diff)
downloadpyfilesystem-204c1602b292ced5653005d84d107b7899989e55.tar.gz
first (very hacky) attempt to prevent timeouts in dokan
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@461 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/expose/dokan')
-rw-r--r--fs/expose/dokan/__init__.py40
-rw-r--r--fs/expose/dokan/libdokan.py2
2 files changed, 40 insertions, 2 deletions
diff --git a/fs/expose/dokan/__init__.py b/fs/expose/dokan/__init__.py
index e5df3d4..7fdaf6a 100644
--- a/fs/expose/dokan/__init__.py
+++ b/fs/expose/dokan/__init__.py
@@ -160,6 +160,7 @@ def handle_fs_errors(func):
_debug("ERR",name,e)
raise
else:
+ _debug("OK",name)
if res is None:
res = 0
if res != 0:
@@ -301,6 +302,12 @@ class FSOperations(object):
return
# Try to open the requested file. It may actually be a directory.
info.contents.Context = 1
+ finished = threading.Event()
+ def reset_timeout_callback():
+ while not finished.isSet():
+ libdokan.DokanResetTimeout(5*60*1000,info)
+ finished.wait(timeout=4*60)
+ threading.Thread(target=reset_timeout_callback).start()
try:
f = self.fs.open(path,mode)
except ResourceInvalidError:
@@ -314,6 +321,8 @@ class FSOperations(object):
raise
else:
info.contents.Context = self._reg_file(f,path)
+ finally:
+ finished.set()
return retcode
@handle_fs_errors
@@ -345,6 +354,12 @@ class FSOperations(object):
self._pending_delete.remove(path)
else:
(file,_,lock) = self._get_file(info.contents.Context)
+ finished = threading.Event()
+ def reset_timeout_callback():
+ while not finished.isSet():
+ libdokan.DokanResetTimeout(5*60*1000,info)
+ finished.wait(timeout=4*60)
+ threading.Thread(target=reset_timeout_callback).start()
lock.acquire()
try:
if info.contents.DeleteOnClose:
@@ -356,17 +371,25 @@ class FSOperations(object):
else:
file.flush()
finally:
+ finished.set()
lock.release()
@handle_fs_errors
def CloseFile(self, path, info):
if info.contents.Context >= MIN_FH:
(file,_,lock) = self._get_file(info.contents.Context)
+ finished = threading.Event()
+ def reset_timeout_callback():
+ while not finished.isSet():
+ libdokan.DokanResetTimeout(5*60*1000,info)
+ finished.wait(timeout=4*60)
+ threading.Thread(target=reset_timeout_callback).start()
lock.acquire()
try:
file.close()
self._del_file(info.contents.Context)
finally:
+ finished.set()
lock.release()
info.contents.Context = 0
@@ -398,8 +421,14 @@ class FSOperations(object):
ctypes.memmove(data,buffer,nBytesToWrite)
file.write(data.raw)
nBytesWritten[0] = len(data.raw)
- if offset + nBytesWritten[0] > self._files_size_written[path][fh]:
- self._files_size_written[path][fh] = offset + nBytesWritten[0]
+ try:
+ size_written = self._files_size_written[path][fh]
+ except KeyError:
+ pass
+ else:
+ if offset + nBytesWritten[0] > size_written:
+ new_size_written = offset + nBytesWritten[0]
+ self._files_size_written[path][fh] = new_size_written
finally:
lock.release()
@@ -509,6 +538,12 @@ class FSOperations(object):
def SetEndOfFile(self, path, length, info):
path = normpath(path)
(file,_,lock) = self._get_file(info.contents.Context)
+ finished = threading.Event()
+ def reset_timeout_callback():
+ while not finished.isSet():
+ libdokan.DokanResetTimeout(5*60*1000,info)
+ finished.wait(timeout=4*60)
+ threading.Thread(target=reset_timeout_callback).start()
lock.acquire()
try:
pos = file.tell()
@@ -518,6 +553,7 @@ class FSOperations(object):
if pos < length:
file.seek(min(pos,length))
finally:
+ finished.set()
lock.release()
@handle_fs_errors
diff --git a/fs/expose/dokan/libdokan.py b/fs/expose/dokan/libdokan.py
index acac583..5391d2c 100644
--- a/fs/expose/dokan/libdokan.py
+++ b/fs/expose/dokan/libdokan.py
@@ -239,6 +239,8 @@ DokanDriverVersion.argtypes = (
DokanResetTimeout = windll.Dokan.DokanResetTimeout
DokanResetTimeout.restype = BOOL
DokanResetTimeout.argtypes = (
+ ULONG, #timeout
+ PDOKAN_FILE_INFO, # file info pointer
)