Commit eef6b392 by willmcgugan

Fixes for zipfs and copydir

parent 068e7dcf
...@@ -569,7 +569,7 @@ class FS(object): ...@@ -569,7 +569,7 @@ class FS(object):
if dst_file is not None: if dst_file is not None:
dst_file.close() dst_file.close()
def move(self, src, dst): def move(self, src, dst, chunk_size=16384):
"""Moves a file from one location to another. """Moves a file from one location to another.
...@@ -586,11 +586,11 @@ class FS(object): ...@@ -586,11 +586,11 @@ class FS(object):
raise ResourceInvalid("WRONG_TYPE", src, msg="Source is not a file: %(path)s") raise ResourceInvalid("WRONG_TYPE", src, msg="Source is not a file: %(path)s")
shutil.move(src_syspath, dst_syspath) shutil.move(src_syspath, dst_syspath)
else: else:
self.copy(src, dst) self.copy(src, dst, chunk_size=chunk_size)
self.remove(src) self.remove(src)
def movedir(self, src, dst, ignore_errors=False): def movedir(self, src, dst, ignore_errors=False, chunk_size=16384):
"""Moves a directory from one location to another. """Moves a directory from one location to another.
...@@ -632,13 +632,13 @@ class FS(object): ...@@ -632,13 +632,13 @@ class FS(object):
src_filename = pathjoin(dirname, filename) src_filename = pathjoin(dirname, filename)
dst_filename = pathjoin(dst_dirpath, filename) dst_filename = pathjoin(dst_dirpath, filename)
movefile(src_filename, dst_filename) movefile(src_filename, dst_filename, chunk_size=chunk_size)
self.removedir(dirname) self.removedir(dirname)
def copydir(self, src, dst, ignore_errors=False): def copydir(self, src, dst, ignore_errors=False, chunk_size=16384):
"""Copies a directory from one location to another. """Copies a directory from one location to another.
...@@ -674,7 +674,7 @@ class FS(object): ...@@ -674,7 +674,7 @@ class FS(object):
src_filename = pathjoin(dirname, filename) src_filename = pathjoin(dirname, filename)
dst_filename = pathjoin(dst_dirpath, filename) dst_filename = pathjoin(dst_dirpath, filename)
copyfile(src_filename, dst_filename) copyfile(src_filename, dst_filename, chunk_size=chunk_size)
def isdirempty(self, path): def isdirempty(self, path):
......
...@@ -72,7 +72,10 @@ class ZipFS(FS): ...@@ -72,7 +72,10 @@ class ZipFS(FS):
raise ValueError("mode must be 'r', 'w' or 'a'") raise ValueError("mode must be 'r', 'w' or 'a'")
self.zip_mode = mode self.zip_mode = mode
self.zf = ZipFile(zip_file, mode, compression_type, allowZip64) try:
self.zf = ZipFile(zip_file, mode, compression_type, allowZip64)
except IOError:
raise ResourceNotFoundError("NO_FILE", "Zip file does not exist: %(path)s")
self.zip_path = str(zip_file) self.zip_path = str(zip_file)
self.temp_fs = None self.temp_fs = None
...@@ -96,7 +99,8 @@ class ZipFS(FS): ...@@ -96,7 +99,8 @@ class ZipFS(FS):
def _add_resource(self, path): def _add_resource(self, path):
if path.endswith('/'): if path.endswith('/'):
path = path[:-1] path = path[:-1]
self._path_fs.makedir(path, recursive=True, allow_recreate=True) if path:
self._path_fs.makedir(path, recursive=True, allow_recreate=True)
else: else:
dirpath, filename = pathsplit(path) dirpath, filename = pathsplit(path)
if dirpath: if dirpath:
......
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