Skip to content

Handle DirEntry as a first-class citizen parameter of file- and path-related functions #10754

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

Draft
wants to merge 60 commits into
base: master
Choose a base branch
from

Conversation

0xEAB
Copy link
Member

@0xEAB 0xEAB commented Apr 18, 2025

I’m opening this as a proof-of-concept PR for my own peace of mind.

Currently, a good chunk of file- and path-related functions accepts DirEntry structures as parameter through implicit conversion to string provided by the alias name this property of DirEntry. This unfortunately comes with the downside that it pins relative paths to the current working directory at the time of the function call. While this is fine in theory, in practice the current working directory might no longer be the one that the string stored in a DirEntry structure is relative to. Though obviously a bug in user code, it also poses an unnecessary footgun — as outlined in #9584.

This could be one of the better ways to solve the underlying issue. I’ve attempted to keep things as backwards-compatible as possible.

The current implementation focuses on Windows where absolute paths are not applicable to restrictions imposed by filesystem permissions of parent directories. A POSIX implementation would likely be more complex and have to involve the usage of more specific system APIs that work on handles instead of path strings and such.

Speaking of #9584, we obviously cannot fix the risks imposed by code that explicitly converts DirEntry to string without greater breakage.

As @jmdavis has already hinted, though, there’s a change we might prefer to call it a day for Phobos v2 and provide an overall better API in Phobos v3.

@0xEAB
Copy link
Member Author

0xEAB commented Apr 18, 2025

Reviewer beware!
I’m fully aware that this still has rough edges.
You might want to focus more on the philosophical aspect of the proposed changes than reviewing the actual code.

@0xEAB 0xEAB changed the title Handle DirEntry as a first-class citizen parameter with file- and path-related functions Handle DirEntry as a first-class citizen parameter of file- and path-related functions Apr 18, 2025
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