Skip to content

Commit 9fc0f5a

Browse files
committed
fs: Accept list of paths in rm.
To comply with fsspec.
1 parent a1f8c64 commit 9fc0f5a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/dvc_objects/fs/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def rmdir(self, path: AnyFSPath) -> None:
378378
def rm_file(self, path: AnyFSPath) -> None:
379379
self.fs.rm_file(path)
380380

381-
def rm(self, path: AnyFSPath) -> None:
381+
def rm(self, path: Union[AnyFSPath, List[AnyFSPath]]) -> None:
382382
self.fs.rm(path, recursive=True)
383383

384384
remove = rm

src/dvc_objects/fs/local.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def rm_file(self, path):
113113
remove(path)
114114

115115
def rm(self, path, recursive=False, maxdepth=None):
116-
remove(path)
116+
if not isinstance(path, list):
117+
path = [path]
118+
for p in path:
119+
remove(p)
117120

118121
def cp_file(self, path1, path2, **kwargs):
119122
return self.copy(path1, path2, **kwargs)

tests/fs/test_localfs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ def test_local_fs_isfile(tmp_path):
5050
assert not fs.isfile(fspath(tmp_path / "not-existing-file"))
5151

5252

53+
def test_local_fs_rm(tmp_path):
54+
(tmp_path / "file").write_text("file", encoding="utf8")
55+
(tmp_path / "file2").write_text("file2", encoding="utf8")
56+
57+
fs = LocalFileSystem()
58+
fs.remove([tmp_path / "file", tmp_path / "file2"])
59+
assert not fs.exists(tmp_path / "file")
60+
assert not fs.exists(tmp_path / "file2")
61+
62+
5363
def convert_to_sets(walk_results):
5464
return [
5565
(root, set(dirs), set(nondirs)) for root, dirs, nondirs in walk_results

0 commit comments

Comments
 (0)