Commit 01b2fd2e by rfkelly0

raise ResourceInvalidError when open() is called on a directory

parent 18e4fae2
...@@ -340,6 +340,8 @@ class MemoryFS(FS): ...@@ -340,6 +340,8 @@ class MemoryFS(FS):
raise ResourceNotFoundError(path) raise ResourceNotFoundError(path)
file_dir_entry = parent_dir_entry.contents[filename] file_dir_entry = parent_dir_entry.contents[filename]
if file_dir_entry.isdir():
raise ResourceInvalidError(path)
if 'a' in mode: if 'a' in mode:
if file_dir_entry.islocked(): if file_dir_entry.islocked():
...@@ -567,4 +569,4 @@ class MemoryFS(FS): ...@@ -567,4 +569,4 @@ class MemoryFS(FS):
@synchronize @synchronize
def listxattrs(self, path): def listxattrs(self, path):
dir_entry = self._dir_entry(path) dir_entry = self._dir_entry(path)
return dir_entry.xattrs.keys() return dir_entry.xattrs.keys()
\ No newline at end of file
...@@ -149,7 +149,14 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): ...@@ -149,7 +149,14 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
@convert_os_errors @convert_os_errors
def open(self, path, mode="r", **kwargs): def open(self, path, mode="r", **kwargs):
mode = filter(lambda c: c in "rwabt+",mode) mode = filter(lambda c: c in "rwabt+",mode)
return open(self.getsyspath(path), mode, kwargs.get("buffering", -1)) sys_path = self.getsyspath(path)
try:
return open(sys_path, mode, kwargs.get("buffering", -1))
except EnvironmentError, e:
# Win32 gives EACCES when opening a directory.
if sys.platform == "win32" and e.errno in (errno.EACCES,):
raise ResourceInvalidError(path)
raise
@convert_os_errors @convert_os_errors
def exists(self, path): def exists(self, path):
...@@ -246,7 +253,7 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): ...@@ -246,7 +253,7 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
# a directory that doesn't exist. We want ParentMissingError # a directory that doesn't exist. We want ParentMissingError
# in this case. # in this case.
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
if not os.path.exists(dirname(path_dst)): if not os.path.exists(os.path.dirname(path_dst)):
raise ParentDirectoryMissingError(dst) raise ParentDirectoryMissingError(dst)
raise raise
......
...@@ -68,6 +68,10 @@ class FSTestCases(object): ...@@ -68,6 +68,10 @@ class FSTestCases(object):
repr(self.fs) repr(self.fs)
self.assert_(hasattr(self.fs, 'desc')) self.assert_(hasattr(self.fs, 'desc'))
def test_open_on_directory(self):
self.fs.makedir("testdir")
self.assertRaises(ResourceInvalidError,self.fs.open,"testdir")
def test_writefile(self): def test_writefile(self):
self.assertRaises(ResourceNotFoundError,self.fs.open,"test1.txt") self.assertRaises(ResourceNotFoundError,self.fs.open,"test1.txt")
f = self.fs.open("test1.txt","w") f = self.fs.open("test1.txt","w")
......
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