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

Fix backward incompatibility introduced in 2.4.16 (#535) #542

Merged
merged 9 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Fixes a backward incompatibility where `fs.move.move_file` raises `DestinationExists`
([#535](https://github.com/PyFilesystem/pyfilesystem2/issues/535)).


## [2.4.16] - 2022-05-02

Expand Down
7 changes: 6 additions & 1 deletion fs/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ def move_file(
rel_dst = frombase(common, dst_syspath)
with _src_fs.lock(), _dst_fs.lock():
with OSFS(common) as base:
base.move(rel_src, rel_dst, preserve_time=preserve_time)
base.move(
rel_src,
rel_dst,
overwrite=True,
preserve_time=preserve_time,
)
return # optimization worked, exit early
except ValueError:
# This is raised if we cannot find a common base folder.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ def test_move_file_read_only_mem_dest(self):
dst_ro.exists("target.txt"), "file should not have been copied over"
)

def test_overwrite(self):
with open_fs("temp://") as src, open_fs("temp://") as dst:
tfeldmann marked this conversation as resolved.
Show resolved Hide resolved
src.writetext("file.txt", "Content")
dst.writetext("target.txt", "Content")
fs.move.move_file(src, "file.txt", dst, "target.txt")
self.assertFalse(src.exists("file.txt"))
self.assertTrue(dst.exists("target.txt"))
lurch marked this conversation as resolved.
Show resolved Hide resolved

@parameterized.expand([(True,), (False,)])
def test_move_file_cleanup_on_error(self, cleanup):
with open_fs("mem://") as src, open_fs("mem://") as dst:
Expand Down