Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalFileSystem.rm support for a sequence of string arguments #678

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ def mv_file(self, path1, path2, **kwargs):
shutil.move(path1, path2)

def rm(self, path, recursive=False, maxdepth=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxdepth is not used in this function...

path = self._strip_protocol(path).rstrip("/")
if recursive and self.isdir(path):
if isinstance(path, str):
path = [path]

if os.path.abspath(path) == os.getcwd():
raise ValueError("Cannot delete current working directory")
shutil.rmtree(path)
else:
os.remove(path)
for p in path:
p = self._strip_protocol(p).rstrip("/")
if recursive and self.isdir(p):

if os.path.abspath(p) == os.getcwd():
raise ValueError("Cannot delete current working directory")
shutil.rmtree(p)
else:
os.remove(p)

def _open(self, path, mode="rb", block_size=None, **kwargs):
path = self._strip_protocol(path)
Expand Down Expand Up @@ -177,7 +181,7 @@ def _isfilestore(self):


def make_path_posix(path, sep=os.sep):
""" Make path generic """
"""Make path generic"""
if isinstance(path, (list, set, tuple)):
return type(path)(make_path_posix(p) for p in path)
if "~" in path:
Expand Down
5 changes: 5 additions & 0 deletions fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ def test_file_ops(tmpdir):
fs.rm(tmpdir + "/afile3", recursive=True)
assert not fs.exists(tmpdir + "/afile3")

files = [tmpdir + "/afile4", tmpdir + "/afile5"]
[fs.touch(f) for f in files]
fs.rm(files)
assert all(not fs.exists(f) for f in files)

fs.rm(tmpdir, recursive=True)
assert not fs.exists(tmpdir)

Expand Down