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

Ensure POSIX path normalizing behavior under NODERAWFS #22372

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

kleisauke
Copy link
Collaborator

@kleisauke kleisauke commented Aug 14, 2024

Avoids mangling C:/tmp to C:\tmp. Should be safe, the underlying Windows API can accept either the backslash or slash to separate directory and file components of a path.

See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Ensures NODERAWFS compatibility on Windows that was regressed since #18163.

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

I'm not sure how this solves the issues since surely /dev/stdin simply doesn't exist on windows (no matter which slashes you use right?)

Can you add @crossplatform to test_noderawfs too?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

Can you mention in the title or description that this is fix for NODERAWFS on windows which was broken by #18163

Avoids mangling `C:/tmp` to `C:\tmp`. Should be safe, the underlying
Windows API can accept either the backslash or slash to separate
directory and file components of a path.

See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Ensures `NODERAWFS` compatibility on Windows that was regressed since
emscripten-core#18163.
@kleisauke kleisauke force-pushed the unbreak-windows-noderawfs branch from 76e6056 to 30def57 Compare August 14, 2024 15:12
@kleisauke
Copy link
Collaborator Author

I'm not sure how this solves the issues since surely /dev/stdin simply doesn't exist on windows (no matter which slashes you use right?)

/dev/stdin is a virtualized path on the filesystem which is reused under NODERAWFS after PR #18163.

// Call the original FS.init, this will setup the
// stdin, stdout and stderr devices
VFS.init(input, output, error);

emscripten/src/library_fs.js

Lines 1415 to 1419 in cd097fb

if (Module['stdin']) {
FS.createDevice('/dev', 'stdin', Module['stdin']);
} else {
FS.symlink('/dev/tty', '/dev/stdin');
}

emscripten/src/library_fs.js

Lines 1357 to 1363 in cd097fb

// setup /dev/tty and /dev/tty1
// stderr needs to print output using err() rather than out()
// so we register a second tty just for it.
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
FS.mkdev('/dev/tty', FS.makedev(5, 0));
FS.mkdev('/dev/tty1', FS.makedev(6, 0));

Can you add @crossplatform to test_noderawfs too?
Can you mention in the title or description that this is fix for NODERAWFS on windows which was broken by #18163

Done.

@kleisauke
Copy link
Collaborator Author

BTW, I'm not sure why the Windows CI actually did pass on #18163. I added @crossplatform to test_module_stdin and test_module_stdout_stderr in that PR, so I expected that test_module_stdin_rawfs and test_module_stdout_stderr_rawfs were also executed under Windows.

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

FS.symlink('/dev/tty', '/dev/stdin');

When this line runs in linux will it actually create symlink in the real /dev/ directory when running under NODERAWFS?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

BTW, I'm not sure why the Windows CI actually did pass on #18163. I added @crossplatform to test_module_stdin and test_module_stdout_stderr in that PR, so I expected that test_module_stdin_rawfs and test_module_stdout_stderr_rawfs were also executed under Windows.

Looks like we were missing @wraps in also_with_noderawfs. I'm got a PR coming to fix that.

@kleisauke
Copy link
Collaborator Author

When this line runs in linux will it actually create symlink in the real /dev/ directory when running under NODERAWFS?

No, since the overwriting occurs later, a virtualized symlink is used.

// Wrap the whole in-memory filesystem API with
// our Node.js based functions
for (var _key in NODERAWFS) {
/** @suppress {partialAlias} */
FS[_key] = _wrapNodeError(NODERAWFS[_key]);
}

@kleisauke
Copy link
Collaborator Author

Looks like we were missing @wraps in also_with_noderawfs.

If you want, I can add that in this PR to verify its correctness.

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

Looks like we were missing @wraps in also_with_noderawfs.

If you want, I can add that in this PR to verify its correctness.

Yup, that makes sense. We can verify the test actually runs. I will still send a PR to make all decorators use @wraps

@sbc100
Copy link
Collaborator

sbc100 commented Aug 14, 2024

BTW, if windows accepts both slashes, why is this change needed?

@kleisauke
Copy link
Collaborator Author

Yup, that makes sense. We can verify the test actually runs. I will still send a PR to make all decorators use @wraps

Great! I just pushed commit eb5869f.

BTW, if windows accepts both slashes, why is this change needed?

Since the virtualized/in-memory file system relies on POSIX/UNIX-style separators.

Details

currentPath: '/',

var parts = path.split('/').filter((p) => !!p);

var current_path = '/';

return mount[mount.length-1] !== '/' ? `${mount}/${path}` : mount + path;

var root = mountpoint === '/';

var dirs = path.split('/');

d += '/' + dirs[i];

FS.mount(MEMFS, {}, '/');

ret.isRoot = lookup.path === '/';

var parts = path.split('/').reverse();

(i.e. that's grep-ing for '/')

@sbc100 sbc100 merged commit 51f0346 into emscripten-core:main Aug 14, 2024
23 of 27 checks passed
@kleisauke kleisauke deleted the unbreak-windows-noderawfs branch August 14, 2024 18:13
@sbc100
Copy link
Collaborator

sbc100 commented Aug 20, 2024

I guess we can/should revert this change too?

@kleisauke
Copy link
Collaborator Author

Indeed, we should probably revert this too after PR #22393 lands.

Sorry for the trouble caused, the good thing is that this found that decorator bug. :)

kleisauke added a commit to kleisauke/emscripten that referenced this pull request Aug 20, 2024
This reverts commit 51f0346.
kleisauke added a commit to kleisauke/emscripten that referenced this pull request Aug 20, 2024
sbc100 pushed a commit that referenced this pull request Aug 21, 2024
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.

2 participants