Skip to content

Conversation

@squeek502
Copy link
Member

@squeek502 squeek502 commented Aug 12, 2023

Previously, a relative path like .. would:

  • Attempt to be normalized (i.e. remove . and .. without any path resolution), but would error with TooManyParentDirs
  • This would make wToPrefixedFileW run it through RtlGetFullPathName_U to do the necessary path resolution, but RtlGetFullPathName_U always resolves relative paths relative to the CWD

Instead, when error.TooManyParentDirs occurs, we now look up the path of the passed in dir (if it's non-null) and append the relative path to it before giving it to RtlGetFullPathName_U. If dir is null, then we just give it RtlGetFullPathName_U directly and let it resolve it relative to the CWD.

Closes #16779


Before this PR, the added test would have failed with something like:

====== expected this output: =========
C:\Users\Ryan\Programming\Zig\zig\zig-cache\tmp\HXPJcC-cI6MVQzvg␃

======== instead found this: =========
C:\Users\Ryan\Programming\Zig␃

======================================
First difference occurs on line 1:
expected:
C:\Users\Ryan\Programming\Zig\zig\zig-cache\tmp\HXPJcC-cI6MVQzvg
                             ^ ('\x5c')
found:
C:\Users\Ryan\Programming\Zig
                             ^ (end of string)

Comment on lines +4446 to +4449
const path_w = windows.sliceToPrefixedFileW(null, path) catch |err| switch (err) {
error.AccessDenied => return error.PermissionDenied,
else => |e| return e,
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #16782

@squeek502 squeek502 force-pushed the fs-too-many-parent-dirs branch 2 times, most recently from e486558 to d9894f1 Compare August 12, 2023 01:37
… cwd-relative

Previously, a relative path like `..` would:
- Attempt to be normalized (i.e. remove . and .. without any path resolution), but would error with TooManyParentDirs
- This would make wToPrefixedFileW run it through `RtlGetFullPathName_U` to do the necessary path resolution, but `RtlGetFullPathName_U` always resolves relative paths relative to the CWD

Instead, when TooManyParentDirs occurs, we now look up the path of the passed in `dir` (if it's non-null) and append the relative path to it before giving it to `RtlGetFullPathName_U`. If `dir` is null, then we just give it RtlGetFullPathName_U directly and let it resolve it relative to the CWD.

Closes ziglang#16779
@squeek502 squeek502 force-pushed the fs-too-many-parent-dirs branch from d9894f1 to 7e542e7 Compare August 12, 2023 01:59
@andrewrk andrewrk merged commit 35b85d3 into ziglang:master Aug 12, 2023
andrewrk added a commit that referenced this pull request Jan 29, 2024
Windows: Fix `TooManyParentDirs` handling for paths that shouldn't be cwd-relative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parent directory (..) does not work on windows

2 participants