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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7484666
Temporarily deprecate `alias this` of `DirEntry`
0xEAB Mar 28, 2025
f7bd085
Add unittest
0xEAB Mar 28, 2025
b2a9d95
Implement `DirEntry` name absolutization for Windows targets
0xEAB Mar 28, 2025
16b587e
Add `DirEntry`-related traits
0xEAB Mar 28, 2025
a5b5393
Convert tabs to spaces
0xEAB Mar 28, 2025
e0ba58e
Add nirvana dir to test
0xEAB Mar 28, 2025
52a9e73
Port `exists()`
0xEAB Mar 28, 2025
cc14345
Mark new unittest Windows-only
0xEAB Mar 28, 2025
2938030
Season attribute soup of `absolutizeName`
0xEAB Mar 28, 2025
78a4b70
Fix internal `DirEntry` ctor
0xEAB Mar 28, 2025
1c9af99
Port `rename()`
0xEAB Mar 30, 2025
a162195
Port `remove()`
0xEAB Mar 30, 2025
f659418
Refactor unittest to be more comprehensible
0xEAB Mar 30, 2025
7405027
Port `getSize()`
0xEAB Mar 30, 2025
d6d971a
Harden file existence tests
0xEAB Mar 30, 2025
9f533b3
Port `getTimes()`
0xEAB Mar 30, 2025
aec92e0
Add yet another file existence test
0xEAB Mar 30, 2025
06a3b17
Port `getTimesWin()`
0xEAB Mar 30, 2025
fd7ccb2
Update `getTimes()` test to match test of `getTimesWin()`
0xEAB Mar 30, 2025
c93ee7d
Refactor `getTimes()` unittests
0xEAB Mar 30, 2025
a968264
Port `setTimes()`
0xEAB Mar 30, 2025
859e7b9
Cleanup unittest
0xEAB Mar 30, 2025
2128737
Port `timeLastModified()`
0xEAB Mar 30, 2025
b5259c9
Use different filenames
0xEAB Mar 30, 2025
9f32604
Simplify file-time warnings code in unittest
0xEAB Mar 30, 2025
55af39d
Improve comment
0xEAB Mar 30, 2025
cd1a14c
Port `getAttributes()` and `getLinkAttributes()`
0xEAB Mar 30, 2025
0ec63ae
Port `setAttributes()`
0xEAB Mar 30, 2025
0d024cb
Port `isFile()` and `isDir()`
0xEAB Mar 30, 2025
22bb441
Improve `isDirEntry` traits
0xEAB Mar 30, 2025
1660809
Refactor scope guards
0xEAB Mar 30, 2025
c2005e4
Port `isSymlink()`
0xEAB Mar 30, 2025
bfc23c2
Port `mkdir()`
0xEAB Mar 30, 2025
41adc42
Port `rmdir()`
0xEAB Mar 30, 2025
60550e3
Port `rmdirRecurse()`
0xEAB Mar 30, 2025
ecd7765
Improve tiny details
0xEAB Mar 30, 2025
4aaa8d1
Port `mkdirRecurse()`
0xEAB Mar 30, 2025
88362b5
Port `getAvailableDiskSpace()`
0xEAB Mar 30, 2025
c63c66e
Port `slurp()`
0xEAB Mar 30, 2025
99d8266
Assert expectations
0xEAB Mar 30, 2025
d5b389e
Port `absolutePath()` and `asAbsolutePath()`
0xEAB Mar 31, 2025
a4ded70
Use proper `Unconst!T`
0xEAB Mar 31, 2025
970550f
Fix `rename()`
0xEAB Mar 31, 2025
2fe4556
Add `rename()` test for dual-`DirEntry`s
0xEAB Mar 31, 2025
e6dfd94
Also test `rename()`ing from `string` to `DirEntry`
0xEAB Mar 31, 2025
4d643d6
Port `copy()`
0xEAB Mar 31, 2025
ce4010a
Harden testing of `rename()`
0xEAB Mar 31, 2025
b8dcae2
Port `readLink()`
0xEAB Mar 31, 2025
3bca43c
Port `relativePath()` and `asRelativePath()`
0xEAB Mar 31, 2025
67de1e7
Port `buildNormalizedPath()` and `asNormalizedPath()`
0xEAB Mar 31, 2025
7d1c4f6
Add test for `dirEntries()` with `chdir()` calls
0xEAB Mar 31, 2025
2ab938e
Document unittest-internal `runIn` function
0xEAB Mar 31, 2025
e426eae
Add changelog entry
0xEAB Apr 4, 2025
5f1a568
Fix Posix branch of `buildNormalizedPath()`
0xEAB Apr 4, 2025
9576d0d
Add backwards compatibility test
0xEAB Apr 4, 2025
7bee62f
Port `dirEntries()`
0xEAB Apr 6, 2025
69d8d24
Enable `rmdirRecurse()` test
0xEAB Apr 6, 2025
90d2283
Fix accidental match of an unexpected function overload
0xEAB Apr 6, 2025
a10ad0e
Add chaotic directory tree traversal test
0xEAB Apr 6, 2025
fbfdce6
Revert "Temporarily deprecate `alias this` of `DirEntry`"
0xEAB Apr 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions changelog/direntries-ng_windows.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Increase more functions accept `DirEntry` on Windows.

The `DirEntry` structure from `std.file` will now capture its absolute path
upon construction on Windows targets.

Unlike POSIX systems, absolute paths are unproblematic on Windows,
as filesystem permissions are evaluated only on the node itself, not by
traversing the whole directory tree along the path.
This means, even if a user has no permission to access to `C:\some-dir\`,
they can still access `C:\some-dir\file` if sufficient permissions are granted
to them for the file entry itself. The same applies to directories.

A good chunk of file-related Phobos functions are “made compatible” with
`DirEntry` through the implicit conversion mechanism provided by `alias this`
found in `DirEntry`. This allows `DirEntry` to become a `string` as needed.

Unfortunately, this comes at the downside that functions can receive a relative
path that is not relative to the current working directory if it has changed
since the construction of the `DirEntry` handle. This does not always align
with the expectations of unsuspecting users — especially in the case where they
have passed a “fat” `DirEntry` handle instead of a raw path string.

Not much can be done in the case where users convert the `DirEntry` into a
`string` on their own. When Phobos functions are called with an actual
`DirEntry`, however, the library can make use of an absolute path that has been
captured in advance and stored in the `DirEntry`.

This describes exactly what has been changed. `std.file` and a number of
functions in `std.path` have been overloaded or modified to also accept a
`DirEntry` parameter in addition to the existing `string` path overloads.

The old behavior can be easily restored either by manually converting a
`DirEntry` to `string` by casting or using the `name` property of said struct.

While this was implemented to be as backwards compatible as reasonably
possible, in certain edge cases a simple adaption to user code might be
necessary. This is the case when users relied on the fact that a relative path
held by a `DirEntry` structure would always be relative to the current working
directory at the time of use. Additionally, rare meta programming code which
assumed that the `string` path overload of applicable functions would get
matched by `DirEntry` structures will have to be updated.
As outlined before, manually converting the `DirEntry` to `string` will do the
trick.

Evidence for the confusing nature of the previous behavior can be found on
the issue tracker:
$(LINK2 https://github.com/dlang/phobos/issues/9584, #9584)

On POSIX the newly introduced overloads currently still emulate the old
behavior. This might be subject to change and should not be relied on.
In general, it is preferable to explicitly use the `name` property of
`DirEntry` in cases where the old behavior is desired.
Loading
Loading