You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On all platforms, this will return error.NotDir if the path is not a directory
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 } to File.OpenFlags and let the caller of Dir.openFile choose which behavior they want
Add a separate Dir.openAny function that can open any type, and make Dir.openFile always return error.IsDir for directory paths on all platforms
Make openFile open any type on all platforms and therefore make that the 'cross-platform' behavior (i.e. don't even have a function that returns error.IsDir when 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 the error.IsDir behavior (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)
Right now, the status quo is:
std.fs.Dir.openFileerror.IsDirif the path is a directory (this is due to.filter = .file_onlyduring thestd.os.windows.OpenFilecall)OpenFlags.isWrite()is true, in which case it will returnerror.IsDir)std.fs.Dir.openDirerror.NotDirif the path is not a directoryThis means that there is currently no cross-platform
std.fs.DirAPI 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:
filter: enum { file_only, any }toFile.OpenFlagsand let the caller ofDir.openFilechoose which behavior they wantDir.openAnyfunction that can open any type, and makeDir.openFilealways returnerror.IsDirfor directory paths on all platformsopenFileopen 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
statcall would be done on non-Windows in the file-only version to get the matchingerror.IsDirbehavior)