Repository navigation
getcwd: drop the \\?\ prefix of a Windows working directory in one reader
#47480
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
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
robobun/8648503c/windows-cwd-long-path-prefix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a636ada
test: a Windows working directory spelled with the `\\?\` prefix
robobun d9237bd
getcwd: drop the `\\?\` prefix of a Windows working directory in one …
robobun 2afff40
test: more of a Windows working directory spelled with the `\\?\` prefix
robobun 11bebdd
test: make the share and volume GUID cases tests of their own
robobun 09b5ef8
test: junction targets that have the `\\?\` prefix, and a Node.js ref…
robobun 35c8494
Merge remote-tracking branch 'origin/main' into robobun/8648503c/wind…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Glob } from "bun"; | ||
| import { expect, test } from "bun:test"; | ||
| import { readFileSync } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| // Windows keeps a `\\?\` prefix in the working directory of a process that starts in, or changes into, a directory | ||
| // spelled with one. `bun_core::getcwd_w` reads the working directory without that prefix, and `bun_core::getcwd` and | ||
| // `bun_sys::getcwd` both read through it. A second reader of `GetCurrentDirectoryW` gives one process two spellings of | ||
| // its working directory. A module path made from the spelling with the prefix is cut at the `?` | ||
| // (https://github.com/oven-sh/bun/issues/11953). | ||
| // | ||
| // Read the working directory with `bun_core::getcwd` or `bun_sys::getcwd`. | ||
| test("the Windows working directory has one reader", async () => { | ||
| const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); | ||
| const call = /(?<!\bfn\s+)\bGetCurrentDirectoryW\s*\(/g; | ||
|
|
||
| const known = new Map([ | ||
| // `getcwd_w`. | ||
| ["src/bun_core/util.rs", 1], | ||
| // The `.bunx` fast path of `bun run <bin>`. Its path does not open with the prefix, and the slower path, which | ||
| // starts the program in the directory as Bun names it, takes over. | ||
| ["src/runtime/cli/run_command.rs", 1], | ||
| // `process.report()` says what the OS says. | ||
| ["src/jsc/bindings/BunProcessReportObjectWindows.cpp", 1], | ||
| ]); | ||
|
|
||
| const found = new Map<string, number>(); | ||
| let scanned = 0; | ||
| for await (const rel of new Glob("**/*.{rs,c,cpp,h}").scan({ cwd: path.join(repoRoot, "src") })) { | ||
| const file = path.join("src", rel).replaceAll("\\", "/"); | ||
| scanned++; | ||
| const source = readFileSync(path.join(repoRoot, file), "utf8"); | ||
| if (!source.includes("GetCurrentDirectoryW")) continue; | ||
| const code = source.split("\n").filter(line => !/^\s*\/\//.test(line)); | ||
| const count = code.join("\n").match(call)?.length ?? 0; | ||
| if (count > 0) found.set(file, count); | ||
| } | ||
| // Guard against repoRoot resolving wrong, which would make the lint pass vacuously. | ||
| expect(scanned).toBeGreaterThan(1000); | ||
| expect(Object.fromEntries([...found].sort())).toEqual(Object.fromEntries([...known].sort())); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.