Skip to content

Commit 8f62e47

Browse files
authored
Avoid deleting memFS's root (#926)
1 parent e5346c8 commit 8f62e47

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

fsspec/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def m():
1717
"""
1818
m = fsspec.filesystem("memory")
1919
m.store.clear()
20-
m.pseudo_dirs.clear()
20+
m.pseudo_dirs = [""]
2121
try:
2222
yield m
2323
finally:

fsspec/implementations/memory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def makedirs(self, path, exist_ok=False):
116116

117117
def rmdir(self, path):
118118
path = self._strip_protocol(path)
119+
if path == "":
120+
# silently avoid deleting FS root
121+
return
119122
if path in self.pseudo_dirs:
120123
if not self.ls(path):
121124
self.pseudo_dirs.remove(path)
@@ -124,7 +127,7 @@ def rmdir(self, path):
124127
else:
125128
raise FileNotFoundError(path)
126129

127-
def exists(self, path):
130+
def exists(self, path, **kwargs):
128131
path = self._strip_protocol(path)
129132
return path in self.store or path in self.pseudo_dirs
130133

fsspec/implementations/tests/test_memory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,9 @@ def test_seekable(m):
150150
f.seek(1)
151151
assert f.read(1) == "a"
152152
assert f.tell() == 2
153+
154+
155+
def test_remove_all(m):
156+
m.touch("afile")
157+
m.rm("/", recursive=True)
158+
assert not m.ls("/")

0 commit comments

Comments
 (0)