Commit 50cdac04 by rfkelly0

add test case for copying files from outside the FS

parent 85772b22
...@@ -513,6 +513,8 @@ class MemoryFS(FS): ...@@ -513,6 +513,8 @@ class MemoryFS(FS):
@synchronize @synchronize
def copydir(self, src, dst, overwrite=False, ignore_errors=False, chunk_size=16384): def copydir(self, src, dst, overwrite=False, ignore_errors=False, chunk_size=16384):
src_dir_entry = self._get_dir_entry(src) src_dir_entry = self._get_dir_entry(src)
if src_dir_entry is None:
raise ResourceNotFoundError(src)
src_xattrs = src_dir_entry.xattrs.copy() src_xattrs = src_dir_entry.xattrs.copy()
super(MemoryFS, self).copydir(src, dst, overwrite, ignore_errors=ignore_errors, chunk_size=chunk_size) super(MemoryFS, self).copydir(src, dst, overwrite, ignore_errors=ignore_errors, chunk_size=chunk_size)
dst_dir_entry = self._get_dir_entry(dst) dst_dir_entry = self._get_dir_entry(dst)
...@@ -522,6 +524,8 @@ class MemoryFS(FS): ...@@ -522,6 +524,8 @@ class MemoryFS(FS):
@synchronize @synchronize
def movedir(self, src, dst, overwrite=False, ignore_errors=False, chunk_size=16384): def movedir(self, src, dst, overwrite=False, ignore_errors=False, chunk_size=16384):
src_dir_entry = self._get_dir_entry(src) src_dir_entry = self._get_dir_entry(src)
if src_dir_entry is None:
raise ResourceNotFoundError(src)
src_xattrs = src_dir_entry.xattrs.copy() src_xattrs = src_dir_entry.xattrs.copy()
super(MemoryFS, self).movedir(src, dst, overwrite, ignore_errors=ignore_errors, chunk_size=chunk_size) super(MemoryFS, self).movedir(src, dst, overwrite, ignore_errors=ignore_errors, chunk_size=chunk_size)
dst_dir_entry = self._get_dir_entry(dst) dst_dir_entry = self._get_dir_entry(dst)
...@@ -531,6 +535,8 @@ class MemoryFS(FS): ...@@ -531,6 +535,8 @@ class MemoryFS(FS):
@synchronize @synchronize
def copy(self, src, dst, overwrite=False, chunk_size=16384): def copy(self, src, dst, overwrite=False, chunk_size=16384):
src_dir_entry = self._get_dir_entry(src) src_dir_entry = self._get_dir_entry(src)
if src_dir_entry is None:
raise ResourceNotFoundError(src)
src_xattrs = src_dir_entry.xattrs.copy() src_xattrs = src_dir_entry.xattrs.copy()
super(MemoryFS, self).copy(src, dst, overwrite, chunk_size) super(MemoryFS, self).copy(src, dst, overwrite, chunk_size)
dst_dir_entry = self._get_dir_entry(dst) dst_dir_entry = self._get_dir_entry(dst)
...@@ -540,6 +546,8 @@ class MemoryFS(FS): ...@@ -540,6 +546,8 @@ class MemoryFS(FS):
@synchronize @synchronize
def move(self, src, dst, overwrite=False, chunk_size=16384): def move(self, src, dst, overwrite=False, chunk_size=16384):
src_dir_entry = self._get_dir_entry(src) src_dir_entry = self._get_dir_entry(src)
if src_dir_entry is None:
raise ResourceNotFoundError(src)
src_xattrs = src_dir_entry.xattrs.copy() src_xattrs = src_dir_entry.xattrs.copy()
super(MemoryFS, self).move(src, dst, overwrite, chunk_size) super(MemoryFS, self).move(src, dst, overwrite, chunk_size)
dst_dir_entry = self._get_dir_entry(dst) dst_dir_entry = self._get_dir_entry(dst)
......
...@@ -122,8 +122,8 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): ...@@ -122,8 +122,8 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
def getsyspath(self, path, allow_none=False): def getsyspath(self, path, allow_none=False):
path = relpath(normpath(path)).replace("/",os.sep) path = relpath(normpath(path)).replace("/",os.sep)
path = os.path.join(self.root_path, path) path = os.path.join(self.root_path, path)
path = self._decode_path(path) path = self._decode_path(path)
return path return path
def unsyspath(self, path): def unsyspath(self, path):
......
...@@ -440,6 +440,11 @@ class FSTestCases(object): ...@@ -440,6 +440,11 @@ class FSTestCases(object):
self.assert_(check("a/foo/bar/baz.txt")) self.assert_(check("a/foo/bar/baz.txt"))
def test_cant_copy_from_os(self):
sys_executable = os.path.abspath(os.path.realpath(sys.executable))
print "COPY", sys_executable
self.assertRaises(FSError,self.fs.copy,sys_executable,"py.exe")
def test_copyfile(self): def test_copyfile(self):
check = self.check check = self.check
contents = "If the implementation is hard to explain, it's a bad idea." contents = "If the implementation is hard to explain, it's a bad idea."
...@@ -457,6 +462,7 @@ class FSTestCases(object): ...@@ -457,6 +462,7 @@ class FSTestCases(object):
self.fs.copy("foo/bar/a.txt", "foo/b.txt") self.fs.copy("foo/bar/a.txt", "foo/b.txt")
self.assert_(check("foo/bar/a.txt")) self.assert_(check("foo/bar/a.txt"))
self.assert_(check("foo/b.txt")) self.assert_(check("foo/b.txt"))
self.assert_(checkcontents("foo/bar/a.txt"))
self.assert_(checkcontents("foo/b.txt")) self.assert_(checkcontents("foo/b.txt"))
self.fs.copy("foo/b.txt", "c.txt") self.fs.copy("foo/b.txt", "c.txt")
......
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