Skip to content

Commit

Permalink
Add missing methods to WrapFS (#321)
Browse files Browse the repository at this point in the history
* fix for makedirs race condition

* changelog

* add missing methods to wrapfs

* added changelog

* fix removetree
  • Loading branch information
willmcgugan committed Jul 28, 2019
1 parent fc29720 commit f274b32
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Restored fs.path import
- Fixed potential race condition in makedirs. Fixes [#310](https://github.com/PyFilesystem/pyfilesystem2/issues/310)
- Added missing methods to WrapFS. Fixed [#294](https://github.com/PyFilesystem/pyfilesystem2/issues/294)

### Changed

Expand Down
43 changes: 41 additions & 2 deletions fs/wrapfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from . import errors
from .base import FS
from .copy import copy_file
from .copy import copy_file, copy_dir
from .info import Info
from .move import move_file
from .move import move_file, move_dir
from .path import abspath, normpath
from .error_tools import unwrap_errors

Expand Down Expand Up @@ -180,6 +180,17 @@ def move(self, src_path, dst_path, overwrite=False):
raise errors.DestinationExists(_dst_path)
move_file(src_fs, _src_path, dst_fs, _dst_path)

def copydir(self, src_path, dst_path, create=False):
# type: (Text, Text, bool) -> None
src_fs, _src_path = self.delegate_path(src_path)
dst_fs, _dst_path = self.delegate_path(dst_path)
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
if not create and not dst_fs.exists(_dst_path):
raise errors.ResourceNotFound(dst_path)
if not src_fs.getinfo(_src_path).is_dir:
raise errors.DirectoryExpected(src_path)
move_dir(src_fs, _src_path, dst_fs, _dst_path)

def openbin(self, path, mode="r", buffering=-1, **options):
# type: (Text, Text, int, **Any) -> BinaryIO
self.check()
Expand All @@ -205,6 +216,16 @@ def removedir(self, path):
with unwrap_errors(path):
_fs.removedir(_path)

def removetree(self, dir_path):
# type: (Text) -> None
self.check()
_path = abspath(normpath(dir_path))
if _path == "/":
raise errors.RemoveRootError()
_fs, _path = self.delegate_path(dir_path)
with unwrap_errors(dir_path):
_fs.removetree(_path)

def scandir(
self,
path, # type: Text
Expand Down Expand Up @@ -247,6 +268,17 @@ def copy(self, src_path, dst_path, overwrite=False):
raise errors.DestinationExists(_dst_path)
copy_file(src_fs, _src_path, dst_fs, _dst_path)

def copydir(self, src_path, dst_path, create=False):
# type: (Text, Text, bool) -> None
src_fs, _src_path = self.delegate_path(src_path)
dst_fs, _dst_path = self.delegate_path(dst_path)
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
if not create and not dst_fs.exists(_dst_path):
raise errors.ResourceNotFound(dst_path)
if not src_fs.getinfo(_src_path).is_dir:
raise errors.DirectoryExpected(src_path)
copy_dir(src_fs, _src_path, dst_fs, _dst_path)

def create(self, path, wipe=False):
# type: (Text, bool) -> bool
self.check()
Expand All @@ -262,6 +294,13 @@ def desc(self, path):
desc = _fs.desc(_path)
return desc

def download(self, path, file, chunk_size=None, **options):
# type: (Text, BinaryIO, Optional[int], **Any) -> None
self.check()
_fs, _path = self.delegate_path(path)
with unwrap_errors(path):
_fs.download(_path, file, chunk_size=chunk_size, **options)

def exists(self, path):
# type: (Text) -> bool
self.check()
Expand Down

0 comments on commit f274b32

Please sign in to comment.