Skip to content

Fix LocalFileSystem directory symlink removal#2074

Merged
martindurant merged 1 commit into
fsspec:masterfrom
Sanjays2402:fix/local-rm-directory-symlink
Jul 14, 2026
Merged

Fix LocalFileSystem directory symlink removal#2074
martindurant merged 1 commit into
fsspec:masterfrom
Sanjays2402:fix/local-rm-directory-symlink

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

LocalFileSystem.rm() treated directory symlinks as directories because isdir() follows links, so removing a link required recursive=True and then routed it through rmtree(). Excluding symlinks from the directory branch unlinks them with os.remove() while leaving the target untouched; the linked-directory test now covers both recursive modes.

Fixes #1299

Test: python -m pytest -q fsspec/implementations/tests/test_local.py (140 passed, 16 skipped)

LocalFileSystem.rm() treated symlinks to directories as directories because
isdir() follows links. This rejected non-recursive removal and routed recursive
removal through shutil.rmtree().

Unlink directory symlinks as files so their targets remain untouched, and cover
both recursive modes in the linked-directory test.

Fixes fsspec#1299
@martindurant
martindurant merged commit 933e992 into fsspec:master Jul 14, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalFileSystem.rm(...) raises an exception when deleting a symlink of a directory

2 participants