Skip to content

Raise IsADirectoryError when opening an implicit directory in MemoryFileSystem - #2180

Open
itzzdev09 wants to merge 1 commit into
fsspec:masterfrom
itzzdev09:hunt-0924
Open

itzzdev09 wants to merge 1 commit into
fsspec:masterfrom
itzzdev09:hunt-0924

Conversation

@itzzdev09

Copy link
Copy Markdown
Contributor

_open only rejected paths in pseudo_dirs (explicit directories created via makedirs), so a path that is a directory only because files live under it — the common case after pipe/touch — could be silently opened as a file, shadowing everything beneath it:

m.pipe('/dir/file', b'data')
m.open('/dir', 'wb')   # used to succeed silently
m.glob('/dir/**')      # -> [] afterwards, file now unreachable
m.head('/dir', 10)     # -> FileExistsError, contradicting what open() just allowed

Fix mirrors the directory check info() already does, and only checks the store (not isdir) so it doesn't add an extra call on the common put/pipe path.

Added a regression test (test_open_implicit_directory_raises) covering rb/wb/ab; confirmed it fails on master without the fix.

🤖 Generated with Claude Code

…ileSystem

_open only rejected paths in pseudo_dirs (explicit dirs from makedirs),
so a path that is a directory only because files live under it (the
common case after pipe/touch) could be silently opened as a file,
shadowing every path beneath it.

>>> m.pipe('/dir/file', b'data')
>>> m.open('/dir', 'wb')  # used to succeed
>>> m.glob('/dir/**')     # -> [] afterwards, file unreachable

Mirrors the directory check info() already does.
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.

1 participant