aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Io/Dir.zig
AgeCommit message (Collapse)Author
5 hoursstd.Io: make file access time optionalAndrew Kelley
Some filesystems, such as ZFS, do not report atime. It's pretty useless in general, so make it an optional field in File.Stat. Also take the opportunity to make setting timestamps API more flexible and match the APIs widely available, which have UTIME_OMIT and UTIME_NOW constants that can be independently set for both fields. This is needed to handle smoothly the case when atime is null.
4 daysDir.readFile/readFileAlloc: take advantage of `.allow_directory = false` on ↵Ryan Liptak
Windows Since we know the read will fail for directories, we can take advantage of Windows being able to fail with IsDir during open to avoid needing to wait until the read to find out about the directory-ness of the file.
4 daysFix sizing of buffer/reservation size for dirReadWindowsRyan Liptak
4 daysstd.Io: implement directory reading for WASIAndrew Kelley
4 daysstd: rename other Dir "make" functions to "create"Andrew Kelley
4 daysstd: rename makeDir to createDir for consistency with createFileAndrew Kelley
4 daysstd.Io.Dir.Reader: fix min_buffer_len on 32-bit linuxAndrew Kelley
dirents64 still uses 8 byte alignment on 32-bit systems
4 daysstd: fix Io.Dir.min_buffer_len on LinuxAndrew Kelley
4 daysstd: Enough fixes to get things compiling on WindowsRyan Liptak
4 daysstd: add support for realpath on file handleAndrew Kelley
and rename OperationNotSupported to OperationUnsupported
4 daysstd.Io.Dir.CopyFileOptions: rename override_permissionsAndrew Kelley
to more simply `permissions`. In master branch this was `override_mode`.
4 daysstd.Io.Dir.renameAbsolute: consistent parameter orderAndrew Kelley
4 daysstd.Io: add unimplemented hard link API to File and DirAndrew Kelley
4 daysstd.Io.Threaded: fix compilation errors on posixAndrew Kelley
4 daysImplement dirReadWindowsRyan Liptak
4 dayscompiler: fix build failures from std.Io-fsAndrew Kelley
4 daysstd.Io: fix dir iteration on macOSAndrew Kelley
4 daysfix build runner compilation errors on macOSAndrew Kelley
4 dayscompiler: fix most compilation errors from std.fs changesAndrew Kelley
4 daysstd.Io.Dir: improve realPath documentationAndrew Kelley
4 dayscompiler: update various code to new fs APIAndrew Kelley
4 daysstd: update fchmodat testsAndrew Kelley
4 daysstd.tar: update fs API calls to take io argumentAndrew Kelley
4 daysstd.Io.Dir: add setFilePermissions and setFileOwnerAndrew Kelley
4 daysstd.Io: implement dir reading for BSDsAndrew Kelley
4 daysstd.Io.Dir: fix walkingAndrew Kelley
* Make Io.Dir.Reader lower level, accepting a buffer. * Make Io.Dir.Iterator higher level, requesting only one Entry with every call to `next`.
4 daysstd.Io: implement dirRead for LinuxAndrew Kelley
unfortunately, Io.Dir.SelectiveWalker is copying the iterator which has multiple problems
4 daysstd: WIP: debug-level stderr writingAndrew Kelley
4 daysbuild_runner compiling againAndrew Kelley
4 daysstd.heap.DebugAllocator: never detect TTY configAndrew Kelley
instead, allow the user to set it as a field. this fixes a bug where leak printing and error printing would run tty config detection for stderr, and then emit a log, which is not necessary going to print to stderr. however, the nice defaults are gone; the user must explicitly assign the tty_config field during initialization or else the logging will not have color. related: https://github.com/ziglang/zig/issues/24510
4 daysfix a handful of compilation errors related to std.fs migrationAndrew Kelley
4 daysupdate all readFileAlloc() to accept Io instanceAndrew Kelley
4 daysupdate all rename() to rename(io)Andrew Kelley
4 daysupdate all access() to access(io)Andrew Kelley
4 daysstd.Io: make all the close functions batchedAndrew Kelley
4 daysupdate all openDir() sites to accept io instanceAndrew Kelley
4 daysstd.fs: migrate most of the API elsewhereAndrew Kelley
4 daysstd: reorganize realpath and process executable APIsAndrew Kelley
4 daysupdate all occurrences of openFile to receive an io instanceAndrew Kelley
4 daysupdate all occurrences of std.fs.Dir to std.Io.DirAndrew Kelley
4 daysupdate all occurrences of close() to close(io)Andrew Kelley
4 daysstd: extract sendfile/copy_file_range from Io.File.WriterAndrew Kelley
and move it into std.Io.Threaded (below the VTable)
4 daysstd: all File functions moved to std.IoAndrew Kelley
4 daysstd: all Dir functions moved to std.IoAndrew Kelley
4 daysstd.Io.Threaded: implement makePathAndrew Kelley
6 dayscompiler,std: remove a handful of redundant discardsMatthew Lugg
I'm embarrassed to say I didn't realise until a few days ago that you could omit the `_` capture for `if`/`while` on `E!void`...
2025-11-21Teach fs.path about the wonderful world of Windows pathsRyan Liptak
Previously, fs.path handled a few of the Windows path types, but not all of them, and only a few of them correctly/consistently. This commit aims to make `std.fs.path` correct and consistent in handling all possible Win32 path types. This commit also slightly nudges the codebase towards a separation of Win32 paths and NT paths, as NT paths are not actually distinguishable from Win32 paths from looking at their contents alone (i.e. `\Device\Foo` could be an NT path or a Win32 rooted path, no way to tell without external context). This commit formalizes `std.fs.path` being fully concerned with Win32 paths, and having no special detection/handling of NT paths. Resources on Windows path types, and Win32 vs NT paths: - https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html - https://chrisdenton.github.io/omnipath/Overview.html - https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file API additions/changes/deprecations - `std.os.windows.getWin32PathType` was added (it is analogous to `RtlDetermineDosPathNameType_U`), while `std.os.windows.getNamespacePrefix` and `std.os.windows.getUnprefixedPathType` were deleted. `getWin32PathType` forms the basis on which the updated `std.fs.path` functions operate. - `std.fs.path.parsePath`, `std.fs.path.parsePathPosix`, and `std.fs.path.parsePathWindows` were added, while `std.fs.path.windowsParsePath` was deprecated. The new `parsePath` functions provide the "root" and the "kind" of a path, which is platform-specific. The now-deprecated `windowsParsePath` did not handle all possible path types, while the new `parsePathWindows` does. - `std.fs.path.diskDesignator` has been deprecated in favor of `std.fs.path.parsePath`, and same deal with `diskDesignatorWindows` -> `parsePathWindows` - `relativeWindows` is now a compile error when *not* targeting Windows, while `relativePosix` is now a compile error when targeting Windows. This is because those functions read/use the CWD path which will behave improperly when used from a system with different path semantics (e.g. calling `relativePosix` from a Windows system with a CWD like `C:\foo\bar` will give you a bogus result since that'd be treated as a single relative component when using POSIX semantics). This also allows `relativeWindows` to use Windows-specific APIs for getting the CWD and environment variables to cut down on allocations. - `componentIterator`/`ComponentIterator.init` have been made infallible. These functions used to be able to error on UNC paths with an empty server component, and on paths that were assumed to be NT paths, but now: + We follow the lead of `RtlDetermineDosPathNameType_U`/`RtlGetFullPathName_U` in how it treats a UNC path with an empty server name (e.g. `\\\share`) and allow it, even if it'll be invalid at the time of usage + Now that `std.fs.path` assumes paths are Win32 paths and not NT paths, we don't have to worry about NT paths Behavior changes - `std.fs.path` generally: any combinations of mixed path separators for UNC paths are universally supported, e.g. `\/server/share`, `/\server\share`, `/\server/\\//share` are all seen as equivalent UNC paths - `resolveWindows` handles all path types more appropriately/consistently. + `//` and `//foo` used to be treated as a relative path, but are now seen as UNC paths + If a rooted/drive-relative path cannot be resolved against anything more definite, the result will remain a rooted/drive-relative path. + I've created [a script to generate the results of a huge number of permutations of different path types](https://gist.github.com/squeek502/9eba7f19cad0d0d970ccafbc30f463bf) (the result of running the script is also included for anyone that'd like to vet the behavior). - `dirnameWindows` now treats the drive-relative root as the dirname of a drive-relative path with a component, e.g. `dirname("C:foo")` is now `C:`, whereas before it would return null. `dirnameWindows` also handles local device paths appropriately now. - `basenameWindows` now handles all path types more appropriately. The most notable change here is `//a` being treated as a partial UNC path now and therefore `basename` will return `""` for it, whereas before it would return `"a"` - `relativeWindows` will now do its best to resolve against the most appropriate CWD for each path, e.g. relative for `D:foo` will look at the CWD to check if the drive letter matches, and if not, look at the special environment variable `=D:` to get the shell-defined CWD for that drive, and if that doesn't exist, then it'll resolve against `D:\`. Implementation details - `resolveWindows` previously looped through the paths twice to build up the relevant info before doing the actual resolution. Now, `resolveWindows` iterates backwards once and keeps track of which paths are actually relevant using a bit set, which also allows it to break from the loop when it's no longer possible for earlier paths to matter. - A standalone test was added to test parts of `relativeWindows` since the CWD resolution logic depends on CWD information from the PEB and environment variables Edge cases worth noting - A strange piece of trivia that I found out while working on this is that it's technically possible to have a drive letter that it outside the intended A-Z range, or even outside the ASCII range entirely. Since we deal with both WTF-8 and WTF-16 paths, `path[0]`/`path[1]`/`path[2]` will not always refer to the same bits of information, so to get consistent behavior, some decision about how to deal with this edge case had to be made. I've made the choice to conform with how `RtlDetermineDosPathNameType_U` works, i.e. treat the first WTF-16 code unit as the drive letter. This means that when working with WTF-8, checking for drive-relative/drive-absolute paths is a bit more complicated. For more details, see the lengthy comment in `std.os.windows.getWin32PathType` - `relativeWindows` will now almost always be able to return either a fully-qualified absolute path or a relative path, but there's one scenario where it may return a rooted path: when the CWD gotten from the PEB is not a drive-absolute or UNC path (if that's actually feasible/possible?). An alternative approach to this scenario might be to resolve against the `HOMEDRIVE` env var if available, and/or default to `C:\` as a last resort in order to guarantee the result of `relative` is never a rooted path. - Partial UNC paths (e.g. `\\server` instead of `\\server\share`) are a bit awkward to handle, generally. Not entirely sure how best to handle them, so there may need to be another pass in the future to iron out any issues that arise. As of now the behavior is: + For `relative`, any part of a UNC disk designator is treated as the "root" and therefore isn't applicable for relative paths, e.g. calling `relative` with `\\server` and `\\server\share` will result in `\\server\share` rather than just `share` and if `relative` is called with `\\server\foo` and `\\server\bar` the result will be `\\server\bar` rather than `..\bar` + For `resolve`, any part of a UNC disk designator is also treated as the "root", but relative and rooted paths are still elligable for filling in missing portions of the disk designator, e.g. `resolve` with `\\server` and `foo` or `\foo` will result in `\\server\foo` Fixes #25703 Closes #25702
2025-10-29std.Io: add dirMakePath and dirMakeOpenPathAndrew Kelley
2025-10-29std.Io: introduce openSelfExeAndrew Kelley
2025-10-29std.Io.Threaded: implement dirOpenFile for WindowsAndrew Kelley