Skip to content

Raise ENAMETOOLONG for path components over NAME_MAX - #1375

Merged
mrbean-bremen merged 3 commits into
pytest-dev:mainfrom
rahul05ranjan:fix/component-length
Nov 18, 2026
Merged

mrbean-bremen merged 3 commits into
pytest-dev:mainfrom
rahul05ranjan:fix/component-length

Conversation

@rahul05ranjan

Copy link
Copy Markdown
Contributor

Describe the changes

Fixes #1374.

The fake filesystem accepted path components longer than NAME_MAX (255 characters under Posix) that the real OS refuses with ENAMETOOLONG. This adds a filesystem-level check (FakeFilesystem._check_component_length, configurable via FakeFilesystem.name_max) applied in the path resolution and creation entry points (resolve_path, lresolve, makedir, remove, rename, create_link).

The check only reports the error when all preceding components resolve, so paths under a missing ancestor keep reporting ENOENT as before. Windows is skipped, as its limits are more complicated and are not emulated.

Tasks

  • Fix or feature added
  • Any AI-generated code has been reviewed line by line
  • Unit tests added that reproduce the issue or prove feature is working
  • Entry to release notes added
  • Pre-commit CI shows no errors
  • Unit tests passing

rahul05ranjan and others added 2 commits November 13, 2026 01:41
The fake filesystem accepted paths with components longer than 255
characters, which the real Posix filesystem refuses with ENAMETOOLONG.
A new filesystem-level check raises the error when a too long component
is reached and all preceding components resolve, so a missing ancestor
still reports ENOENT as before.

Fixes pytest-dev#1374

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Comment thread CHANGES.md
under Posix) silently succeeding instead of raising `ENAMETOOLONG`
in the fake filesystem, for example in `os.mkdir`, `os.stat`, `os.listdir`,
`os.remove`, `os.truncate`, `os.rename`, `os.link` and file open
(see [issue #1374](https://github.com/pytest-dev/pyfakefs/issues/1374))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to list all examples here (this is what the link to the issue is for), I prefer shorter release notes entries for readability. For example:

  • path operations on paths with too long path components now correctly raise ENAMETOOLONG under Posix (see ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — shortened the entry following your suggested wording, thanks! (commit 22d7c88)

Shorten the release notes entry as requested by the review, following
the reviewer's preferred short style for readability.

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>

@mrbean-bremen mrbean-bremen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@mrbean-bremen
mrbean-bremen merged commit ed324a9 into pytest-dev:main Nov 18, 2026
103 of 104 checks passed
@rahul05ranjan

Copy link
Copy Markdown
Contributor Author

Merged — thank you! Glad the release-notes entry landed in the short style. Nice to see it merged the same day the fix went up.

On a personal note: I'm on the lookout for my next role (Full Stack (PHP, NodeJs, Python) / Data Science / Applied AI / Devtools, based in India). Happy to chat if there's an opening on your side or one you'd recommend:
LinkedIn: https://www.linkedin.com/in/rahulswt7/ · GitHub: https://github.com/rahul05ranjan

@mrbean-bremen

Copy link
Copy Markdown
Member

Can't help with the job. This project is purely free-time, and my day job does not fit your skills (and we are not hiring).

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.

Path components longer than NAME_MAX (255) succeed instead of raising ENAMETOOLONG

2 participants