Skip to content

Commit 6763644

Browse files
committed
add default overwrite arg (fixes #535)
1 parent 50b1c99 commit 6763644

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

fs/move.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ def move_file(
8282
rel_dst = frombase(common, dst_syspath)
8383
with _src_fs.lock(), _dst_fs.lock():
8484
with OSFS(common) as base:
85-
base.move(rel_src, rel_dst, preserve_time=preserve_time)
85+
base.move(
86+
rel_src,
87+
rel_dst,
88+
overwrite=True,
89+
preserve_time=preserve_time,
90+
)
8691
return # optimization worked, exit early
8792
except ValueError:
8893
# This is raised if we cannot find a common base folder.

tests/test_move.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ def test_move_file_read_only_mem_dest(self):
151151
dst_ro.exists("target.txt"), "file should not have been copied over"
152152
)
153153

154+
def test_overwrite(self):
155+
with open_fs("temp://") as src, open_fs("temp://") as dst:
156+
src.writetext("file.txt", "Content")
157+
dst.writetext("target.txt", "Content")
158+
fs.move.move_file(src, "file.txt", dst, "target.txt")
159+
self.assertFalse(src.exists("file.txt"))
160+
self.assertTrue(dst.exists("target.txt"))
161+
154162
@parameterized.expand([(True,), (False,)])
155163
def test_move_file_cleanup_on_error(self, cleanup):
156164
with open_fs("mem://") as src, open_fs("mem://") as dst:

0 commit comments

Comments
 (0)