Skip to content

Zig fmt fails to open local-path files #4605

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

Closed
BarabasGitHub opened this issue Mar 2, 2020 · 5 comments
Closed

Zig fmt fails to open local-path files #4605

BarabasGitHub opened this issue Mar 2, 2020 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@BarabasGitHub
Copy link
Contributor

Zig 0.5.0+6a0927d8c on Windows

The file window.zig exists, but these fail. Just using zig fmt window.zig works fine.

PS C:\Projects\ZigVulkan> zig fmt .\window.zig
unable to open '.\window.zig': error.FileNotFound
PS C:\Projects\ZigVulkan> zig fmt ./window.zig
unable to open './window.zig': error.BadPathName

For the second one I guess it's the same as #2668

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-windows labels Mar 2, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Mar 2, 2020
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Mar 2, 2020
@squeek502
Copy link
Collaborator

squeek502 commented Mar 3, 2020

As far as I can tell, NtCreateFile treats ObjectName literally and doesn't do any resolving, so it's actually searching for the impossible path C:\Projects\ZigVulkan\.\window.zig. To fix this particular issue, it seems like either paths need to always be resolved before calls to std.fs.openFileWindows or resolved within std.fs.openFileWindows (and other callers of NtCreateFile?).

Also worth noting that .. as a directory in ObjectName is invalid and gives an STATUS_OBJECT_NAME_INVALID error (0xC0000033):

  • zig fmt ..\test.zig -> error.Unexpected NTSTATUS=0xc0000033
  • zig fmt test\..\test.zig -> error.Unexpected NTSTATUS=0xc0000033
  • zig fmt test..\test.zig -> error.FileNotFound (accurate, that file didn't exist)

@daurnimator
Copy link
Contributor

Pre-resolving has huge implications for following symlinks (called/using "reparse points" in NT-speak). I don't think its required, but will need to do some research.

@squeek502
Copy link
Collaborator

Tiny reproduction:

const std = @import("std");

test "windows open file" {
    var first = try std.fs.cwd().openFile("test.zig", .{});
    first.close();

    var second = try std.fs.cwd().openFile(".\\test.zig", .{});
    second.close();
}

If test.zig exists, the first open succeeds, but the second fails, even though they would resolve to the same path.

@daurnimator
Copy link
Contributor

So I did some research, and processing '..' on windows requires a dance where you use NtQueryInformationFile + NtOpenFile to traverse up a directory for each time you encounter '..'.
There is an example at: https://git.midipix.org/ntapi/tree/src/fs/ntapi_tt_open_physical_parent_directory.c

@squeek502
Copy link
Collaborator

This can be closed now (fixed by #5187)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants