zig/lib/std/os
Ryan Liptak 49053cb1b4 Add fs.path.ComponentIterator and use it in Dir.makePath
Before this commit, there were three issues with the makePath implementation:

1. The component iteration did not 'collapse' consecutive path separators; instead, it would treat `a/b//c` as `a/b//c`, `a/b/`, `a/b`, and `a`.
2. Trailing path separators led to redundant `makeDir` calls, e.g. with the path `a/b/` (if `a` doesn't exist), it would try to create `a/b/`, then try `a/b`, then try `a`, then try `a/b`, and finally try `a/b/` again.
3. The iteration did not treat the root of a path specially, so on Windows it could attempt to make a directory with a path like `X:` for something like `X:\a\b\c` if the `X:\` drive doesn't exist. This didn't lead to any problems that I could find, but there's no reason to try to make a drive letter as a directory (or any other root path).

This commit fixes all three issues by introducing a ComponentIterator that is root-aware and handles both sequential path separators and trailing path separators and uses it in `Dir.makePath`. This reduces the number of `makeDir` calls for paths where (1) the root of the path doesn't exist, (2) there are consecutive path separators, or (3) there are trailing path separators

As an example, here are the makeDir calls that would have been made before this commit when calling `makePath` for a relative path like `a/b//c//` (where the full path needs to be created):

a/b//c//
a/b//c/
a/b//c
a/b/
a/b
a
a/b
a/b/
a/b//c
a/b//c/
a/b//c//

And after this commit:

a/b//c
a/b
a
a/b
a/b//c
2023-07-27 10:22:54 -07:00
..
linux io_uring: let the OS choose a free local port for all tests 2023-07-24 20:12:41 -07:00
plan9 all: zig fmt and rename "@XToY" to "@YFromX" 2023-06-19 12:34:42 -07:00
uefi more UEFI alignment fixes 2023-07-20 12:46:33 -07:00
windows Use builtin inference over @as where possible 2023-07-24 10:23:51 -07:00
linux.zig std.os.linux | Fix sendmmsg function | Issue #16513 2023-07-25 11:04:10 -07:00
plan9.zig all: migrate code to new cast builtin syntax 2023-06-24 16:56:39 -07:00
test.zig all: migrate code to new cast builtin syntax 2023-06-24 16:56:39 -07:00
uefi.zig std.os.uefi: use std.os.uefi.cc instead of .C as calling convention 2023-07-08 17:32:36 -04:00
wasi.zig all: migrate code to new cast builtin syntax 2023-06-24 16:56:39 -07:00
windows.zig Add fs.path.ComponentIterator and use it in Dir.makePath 2023-07-27 10:22:54 -07:00