Skip to content

Zig fmt fails to open local-path files #4605

Closed

Description

@BarabasGitHub

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

Activity

  1. added
    bug
    contributor friendly
    os-windows
    on Mar 2, 2020
  2. added this to the 0.7.0 milestone on Mar 2, 2020
  3. added
    standard library
    on Mar 2, 2020
  4. squeek502 commented on Mar 3, 2020

    @squeek502
    Member

    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)
  5. daurnimator commented on Mar 3, 2020

    @daurnimator
    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.

  6. squeek502 commented on Mar 3, 2020

    @squeek502
    Member

    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.

  7. daurnimator commented on Mar 4, 2020

    @daurnimator
    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

  8. squeek502 commented on Apr 28, 2020

    @squeek502
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcontributor friendlyos-windowsstandard library

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions