-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Right now, the status quo is:
std.fs.Dir.openFile- On Windows, this will return
error.IsDirif the path is a directory (this is due to.filter = .file_onlyduring thestd.os.windows.OpenFilecall) - On non-Windows, this will succeed if the path is a directory (unless
OpenFlags.isWrite()is true, in which case it will returnerror.IsDir) - (this discrepancy is tracked in Platform specific error.IsDir behavior in fs.Dir.openFile #5732)
- On Windows, this will return
std.fs.Dir.openDir- On all platforms, this will return
error.NotDirif the path is not a directory
- On all platforms, this will return
This means that there is currently no cross-platform std.fs.Dir API that allows opening any path (regardless of its type). Having an API that allows opening any path on all platforms is possible, though, and would be useful (see https://ziggit.dev/t/how-to-check-if-path-points-to-a-file-or-a-directory/).
There are a few ways that this could be addressed:
- Add
filter: enum { file_only, any }toFile.OpenFlagsand let the caller ofDir.openFilechoose which behavior they want - Add a separate
Dir.openAnyfunction that can open any type, and makeDir.openFilealways returnerror.IsDirfor directory paths on all platforms - Make
openFileopen any type on all platforms and therefore make that the 'cross-platform' behavior (i.e. don't even have a function that returnserror.IsDirwhen opening a directory as read-only) [this is the option I prefer the least, since it means that you'd have to do a stat call afterwards if you wanted theerror.IsDirbehavior (which wouldn't be necessary on windows if OpenFile was just called with.file_only)]
Note that all of these options would effectively close #5732 (since in option 1 & 2, a stat call would be done on non-Windows in the file-only version to get the matching error.IsDir behavior)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.