Skip to content

Commit c01b6c8

Browse files
daavooefiop
authored andcommitted
fs: Accept list of paths in rm.
To comply with fsspec.
1 parent 15c271a commit c01b6c8

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/dvc_objects/fs/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,13 @@ def rmdir(self, path: AnyFSPath) -> None:
449449
def rm_file(self, path: AnyFSPath) -> None:
450450
self.fs.rm_file(path)
451451

452-
def rm(self, path: AnyFSPath) -> None:
453-
self.fs.rm(path, recursive=True)
452+
def rm(
453+
self,
454+
path: Union[AnyFSPath, List[AnyFSPath]],
455+
recursive: bool = False,
456+
**kwargs,
457+
) -> None:
458+
self.fs.rm(path, recursive=recursive, **kwargs)
454459

455460
remove = rm
456461

src/dvc_objects/fs/local.py

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

112112
def rm(self, path, recursive=False, maxdepth=None):
113-
remove(path)
113+
if isinstance(path, str):
114+
path = [path]
115+
for p in path:
116+
remove(p)
114117

115118
def cp_file(self, path1, path2, **kwargs):
116119
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)