Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update movedir methods of WrapFS to use the delegate FS method #511

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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