Skip to content

Commit

Permalink
Merge pull request #511 from PyFilesystem/fix-wrapfs-move
Browse files Browse the repository at this point in the history
Update `movedir` methods of `WrapFS` to use the delegate FS method
  • Loading branch information
althonos committed Feb 7, 2022
2 parents a6ea045 + df36726 commit 63719b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
resources, causing `MemoryFS.scandir` to use the old name.
([#510](https://github.com/PyFilesystem/pyfilesystem2/pull/510)).
Closes [#509](https://github.com/PyFilesystem/pyfilesystem2/issues/509).
- Make `WrapFS.move` and `WrapFS.movedir` use the delegate FS methods instead
of `fs.move` functions, which was causing optimized implementation of
`movedir` to be always skipped.
([#511](https://github.com/PyFilesystem/pyfilesystem2/pull/511)).


## [2.4.14] - 2021-11-16
Expand Down
24 changes: 10 additions & 14 deletions fs/wrapfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .base import FS
from .copy import copy_file, copy_dir
from .info import Info
from .move import move_file, move_dir
from .path import abspath, join, normpath
from .error_tools import unwrap_errors

Expand Down Expand Up @@ -169,24 +168,21 @@ def makedir(

def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
# type: (Text, Text, bool, bool) -> None
# A custom move permits a potentially optimized code path
src_fs, _src_path = self.delegate_path(src_path)
dst_fs, _dst_path = self.delegate_path(dst_path)
_fs, _src_path = self.delegate_path(src_path)
_, _dst_path = self.delegate_path(dst_path)
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
if not overwrite and dst_fs.exists(_dst_path):
raise errors.DestinationExists(_dst_path)
move_file(src_fs, _src_path, dst_fs, _dst_path, preserve_time=preserve_time)
_fs.move(
_src_path, _dst_path, overwrite=overwrite, preserve_time=preserve_time
)

def movedir(self, src_path, dst_path, create=False, preserve_time=False):
# type: (Text, Text, bool, bool) -> None
src_fs, _src_path = self.delegate_path(src_path)
dst_fs, _dst_path = self.delegate_path(dst_path)
_fs, _src_path = self.delegate_path(src_path)
_, _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, preserve_time=preserve_time)
_fs.movedir(
_src_path, _dst_path, create=create, preserve_time=preserve_time
)

def openbin(self, path, mode="r", buffering=-1, **options):
# type: (Text, Text, int, **Any) -> BinaryIO
Expand Down

0 comments on commit 63719b1

Please sign in to comment.