Skip to content

fix(mem): return EISDIR when reading from directory handles#610

Open
leno23 wants to merge 1 commit into
spf13:masterfrom
leno23:fix/mem-readfile-directory-eisdir
Open

fix(mem): return EISDIR when reading from directory handles#610
leno23 wants to merge 1 commit into
spf13:masterfrom
leno23:fix/mem-readfile-directory-eisdir

Conversation

@leno23

@leno23 leno23 commented May 25, 2026

Copy link
Copy Markdown

Summary

Fixes #201

afero.ReadFile on a directory path with MemMapFs previously returned empty data without error. The in-memory file handle allowed Read/ReadAt on directory nodes.

This change aligns mem.File with tarfs, zipfs, and gcsfs by returning a PathError wrapping syscall.EISDIR for read, write, seek, and truncate operations on directories.

Test plan

  • go test ./...
  • Added TestReadFileDirectoryMemMapFs

MemMapFs allowed ReadFile to succeed on directories because mem.File
ReadAt did not reject directory handles. Align with os and other afero
filesystems by returning a PathError wrapping syscall.EISDIR.

Fixes spf13#201

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


wuyangfan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@spf13

spf13 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Thanks for these contributions. Before we can review and merge, you'll need to sign the Contributor License Agreement (CLA). Please do so and then let us know — we'll pick up the review from there.

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.

afero.ReadFile doesn't return error when filename is a directory when fs is memmapfs

3 participants