Skip to content

Commit 63719b1

Browse files
authored
Merge pull request #511 from PyFilesystem/fix-wrapfs-move
Update `movedir` methods of `WrapFS` to use the delegate FS method
2 parents a6ea045 + df36726 commit 63719b1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2020
resources, causing `MemoryFS.scandir` to use the old name.
2121
([#510](https://github.com/PyFilesystem/pyfilesystem2/pull/510)).
2222
Closes [#509](https://github.com/PyFilesystem/pyfilesystem2/issues/509).
23+
- Make `WrapFS.move` and `WrapFS.movedir` use the delegate FS methods instead
24+
of `fs.move` functions, which was causing optimized implementation of
25+
`movedir` to be always skipped.
26+
([#511](https://github.com/PyFilesystem/pyfilesystem2/pull/511)).
2327

2428

2529
## [2.4.14] - 2021-11-16

fs/wrapfs.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .base import FS
1212
from .copy import copy_file, copy_dir
1313
from .info import Info
14-
from .move import move_file, move_dir
1514
from .path import abspath, join, normpath
1615
from .error_tools import unwrap_errors
1716

@@ -169,24 +168,21 @@ def makedir(
169168

170169
def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
171170
# type: (Text, Text, bool, bool) -> None
172-
# A custom move permits a potentially optimized code path
173-
src_fs, _src_path = self.delegate_path(src_path)
174-
dst_fs, _dst_path = self.delegate_path(dst_path)
171+
_fs, _src_path = self.delegate_path(src_path)
172+
_, _dst_path = self.delegate_path(dst_path)
175173
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
176-
if not overwrite and dst_fs.exists(_dst_path):
177-
raise errors.DestinationExists(_dst_path)
178-
move_file(src_fs, _src_path, dst_fs, _dst_path, preserve_time=preserve_time)
174+
_fs.move(
175+
_src_path, _dst_path, overwrite=overwrite, preserve_time=preserve_time
176+
)
179177

180178
def movedir(self, src_path, dst_path, create=False, preserve_time=False):
181179
# type: (Text, Text, bool, bool) -> None
182-
src_fs, _src_path = self.delegate_path(src_path)
183-
dst_fs, _dst_path = self.delegate_path(dst_path)
180+
_fs, _src_path = self.delegate_path(src_path)
181+
_, _dst_path = self.delegate_path(dst_path)
184182
with unwrap_errors({_src_path: src_path, _dst_path: dst_path}):
185-
if not create and not dst_fs.exists(_dst_path):
186-
raise errors.ResourceNotFound(dst_path)
187-
if not src_fs.getinfo(_src_path).is_dir:
188-
raise errors.DirectoryExpected(src_path)
189-
move_dir(src_fs, _src_path, dst_fs, _dst_path, preserve_time=preserve_time)
183+
_fs.movedir(
184+
_src_path, _dst_path, create=create, preserve_time=preserve_time
185+
)
190186

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

0 commit comments

Comments
 (0)