phobos icon indicating copy to clipboard operation
phobos copied to clipboard

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

Open 0xEAB opened this issue 10 months ago • 1 comments

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 avatar Apr 18 '25 22:04 0xEAB

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 avatar Apr 18 '25 22:04 0xEAB

This PR has had a broken CI for 6+ months, please reopen if you plan to continue working on this.

LightBender avatar Oct 27 '25 01:10 LightBender