Skip to content
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

Windows #hostPreopen causes all drive paths to be error #555

Open
oovm opened this issue Jan 29, 2025 · 1 comment
Open

Windows #hostPreopen causes all drive paths to be error #555

oovm opened this issue Jan 29, 2025 · 1 comment

Comments

@oovm
Copy link

oovm commented Jan 29, 2025

This logic is not correct on Windows, as nodejs does not support drive letters starting with // or \\\\

if (descriptor.#hostPreopen)
return (
descriptor.#hostPreopen +
(descriptor.#hostPreopen.endsWith("/")
? ""
: subpath.length > 0
? "/"
: "") +
subpath
);

here #hostPreopen = '//' in default case on windows, leads all drive path start with //.


We can use the following code as a quick test:

// PS C:\> node -v                                                                    
// v22.12.0
import {opendir} from "node:fs/promises";

const dir1 = await opendir("C:\\")
const dir2 = await opendir("\\\\C:\\") // error

const dir3 = await opendir("C:/")
const dir4 = await opendir("//C:/")    // error
node:fs:561
  return binding.open(
                 ^

Error: UNKNOWN: unknown error, open '//C:/'
    at openSync (node:fs:561:18)
    at Descriptor.openAt (file:///@bytecodealliance/preview2-shim/lib/nodejs/filesystem.js:374:18)
    at wasm://wasm/87d42ad6:wasm-function[21]:0x293
    at wasm://wasm/4fc715b2:wasm-function[77]:0x3004
    at wasm://wasm/87d42ad6:wasm-function[5]:0x1c7
    at wasm://wasm/013b0f46:wasm-function[1623]:0x15797e
    at wasm://wasm/013b0f46:wasm-function[166]:0x4de15
    at wasm://wasm/013b0f46:wasm-function[152]:0x4a64b
    at wasm://wasm/013b0f46:wasm-function[1605]:0x154f49 {
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'open',
  path: '\\\\C:\\'
}
@guybedford
Copy link
Collaborator

Currently we recommend forward-slash UNC paths like //?/C:/Path/To/File.txt for Windows paths. Personally I think that's the better cross platform technique, but I know it's not for everyone. Fully supporting non-UNC Windows paths is still a TODO in the WASI implementation.

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

No branches or pull requests

2 participants