Commit 034643b5 by rfkelly0

dokan: correctly handle CreateFile with disposition=CREATE_NEW

parent ccf6c09e
......@@ -143,16 +143,22 @@ def handle_fs_errors(func):
func = convert_fs_errors(func)
@wraps(func)
def wrapper(*args,**kwds):
#print "CALL", name, args[1:-1]; sys.stdout.flush()
try:
res = func(*args,**kwds)
except OSError, e:
#print "ERR", name, e
if e.errno:
res = -1 * _errno2syserrcode(e.errno)
else:
res = -1
except Exception, e:
#print "ERR", name, e
raise
else:
if res is None:
res = 0
#print "RES", name, res; sys.stdout.flush()
return res
return wrapper
......@@ -238,6 +244,10 @@ class FSOperations(DokanOperations):
if not self.fs.exists(path):
raise ResourceNotFoundError(path)
mode = "w+b"
elif disposition == CREATE_NEW:
if self.fs.exists(path):
return -183
mode = "w+b"
else:
mode = "r+b"
else:
......@@ -255,6 +265,10 @@ class FSOperations(DokanOperations):
if not self.fs.exists(path):
raise ResourceNotFoundError(path)
mode = "w+b"
elif disposition == CREATE_NEW:
if self.fs.exists(path):
return -183
mode = "w+b"
else:
mode = "r+b"
# Try to open the requested file. It may actually be a directory.
......@@ -707,10 +721,16 @@ class MountProcess(subprocess.Popen):
if __name__ == "__main__":
import os, os.path
from fs.tempfs import TempFS
fs = TempFS()
import tempfile
from fs.osfs import OSFS
path = tempfile.mkdtemp()
try:
fs = OSFS(path)
fs.setcontents("test1.txt","test one")
flags = DOKAN_OPTION_DEBUG|DOKAN_OPTION_STDERR|DOKAN_OPTION_REMOVABLE
mount(fs, "Q", foreground=True, numthreads=1, flags=flags)
fs.close()
finally:
OSFS(path).removedir("/",force=True)
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