Skip to content

Commit c686cdf

Browse files
authored
make localFS mv() respect auto_mkdir (#1957)
1 parent f199984 commit c686cdf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

fsspec/implementations/local.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ def mv(self, path1, path2, recursive: bool = True, **kwargs):
166166
"""
167167
path1 = self._strip_protocol(path1)
168168
path2 = self._strip_protocol(path2)
169+
170+
if self.auto_mkdir:
171+
self.makedirs(self._parent(path2), exist_ok=True)
172+
169173
shutil.move(path1, path2)
170174

171175
def link(self, src, dst, **kwargs):

fsspec/implementations/tests/test_local.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,24 @@ def test_mv_recursive(tmpdir):
10431043
assert localfs.info(os.path.join(dest, "afile"))
10441044

10451045

1046+
def test_mv_auto_mkdir(tmpdir):
1047+
localfs = fsspec.filesystem("file", auto_mkdir=True)
1048+
src = os.path.join(str(tmpdir), "src")
1049+
dest_dir = os.path.join(str(tmpdir), "dest_dir")
1050+
dest = os.path.join(dest_dir, "dest")
1051+
1052+
assert localfs.exists(src) is False
1053+
assert localfs.exists(dest) is False
1054+
assert localfs.exists(dest_dir) is False
1055+
1056+
localfs.touch(src)
1057+
localfs.mv(src, dest)
1058+
1059+
assert localfs.exists(src) is False
1060+
assert localfs.isfile(dest)
1061+
assert localfs.info(dest)
1062+
1063+
10461064
@pytest.mark.xfail(WIN, reason="windows expand path to be revisited")
10471065
def test_copy_errors(tmpdir):
10481066
localfs = fsspec.filesystem("file", auto_mkdir=True)

0 commit comments

Comments
 (0)