Skip to content

Commit f357bb1

Browse files
authored
[PHP-wasm Node] Remove unused node creation code from createNodeFsMountHandler (#2379)
## Motivation for the change, related issues While testing symlink issues in the Playground CLI, I realized that `statSync(localPath).isSymbolicLink()` will always be false because `statSync` follows symlinks. When I fixed that issue, I realized that symlinks must be mounted as either files or directories, otherwise the `FS.lookupPath` will always [throw errno 44 for the symlinked path.](https://github.com/WordPress/wordpress-playground/blob/trunk/packages/php-wasm/node/asyncify/php_8_0.js#L3572) This PR doesn't change any PHP-wasm behavior; it only removes unused code. ## Testing Instructions (or ideally a Blueprint) - CI
1 parent 2cae5ab commit f357bb1

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/php-wasm/node/src/lib/node-fs-mount.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { FSHelpers, type MountHandler } from '@php-wasm/universal';
2-
import { statSync } from 'fs';
3-
import { basename, dirname } from 'path';
1+
import {
2+
type Emscripten,
3+
FSHelpers,
4+
type MountHandler,
5+
} from '@php-wasm/universal';
6+
import { lstatSync } from 'fs';
7+
import { dirname } from 'path';
48

59
export function createNodeFsMountHandler(localPath: string): MountHandler {
610
return function (php, FS, vfsMountPoint) {
@@ -19,17 +23,11 @@ export function createNodeFsMountHandler(localPath: string): MountHandler {
1923
*/
2024
let removeVfsNode = false;
2125
if (!FSHelpers.fileExists(FS, vfsMountPoint)) {
22-
if (statSync(localPath).isSymbolicLink()) {
23-
FS.mkdirTree(dirname(vfsMountPoint));
24-
(FS as any).createNode(
25-
FS.lookupPath(vfsMountPoint, { parent: true }).node,
26-
basename(localPath),
27-
110000
28-
);
29-
} else if (statSync(localPath).isFile()) {
26+
const lstat = lstatSync(localPath);
27+
if (lstat.isFile() || lstat.isSymbolicLink()) {
3028
FS.mkdirTree(dirname(vfsMountPoint));
3129
FS.writeFile(vfsMountPoint, '');
32-
} else if (statSync(localPath).isDirectory()) {
30+
} else if (lstat.isDirectory()) {
3331
FS.mkdirTree(vfsMountPoint);
3432
} else {
3533
throw new Error(
@@ -38,9 +36,17 @@ export function createNodeFsMountHandler(localPath: string): MountHandler {
3836
}
3937
removeVfsNode = true;
4038
}
41-
const lookup = FS.lookupPath(vfsMountPoint);
42-
if (!lookup.node) {
43-
throw new Error('Unable to access the mount point in VFS.');
39+
let lookup: Emscripten.FS.Lookup | undefined;
40+
try {
41+
lookup = FS.lookupPath(vfsMountPoint);
42+
} catch (e) {
43+
const error = e as Emscripten.FS.ErrnoError;
44+
if (error.errno === 44) {
45+
throw new Error(
46+
`Unable to access the mount point ${vfsMountPoint} in VFS after attempting to create it.`
47+
);
48+
}
49+
throw e;
4450
}
4551
FS.mount(FS.filesystems['NODEFS'], { root: localPath }, vfsMountPoint);
4652
return () => {

0 commit comments

Comments
 (0)