Skip to content

Commit 92d0ce7

Browse files
committed
Force follow to always be true in FS.lookupPath
1 parent 9a9262c commit 92d0ce7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/php-wasm/node/src/lib/load-runtime.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ export async function loadNodeRuntime(
9191
* for the path and Emscripten will accept it as if it was the real link path.
9292
*/
9393
if (options?.followSymlinks === true) {
94+
/**
95+
* PHP might call `lookupPath` with `follow: false`.
96+
* When this happens Emscripten will not follow the symlink when it's the final path component.
97+
* This happens for example during a is_dir check or lstat.
98+
*
99+
* To work around this, we override the `lookupPath` function to always follow the symlink.
100+
*
101+
* TODO:
102+
* - Understand why we must override follow: false when it's explicitly required by the caller.
103+
* - Find a way to set follow: true as the default behavior, but allow the caller to override it.
104+
*/
105+
const lookupPath = phpRuntime.FS.lookupPath;
106+
phpRuntime.FS.lookupPath = (
107+
path: string,
108+
options: any = {}
109+
) => {
110+
return lookupPath(path, {
111+
...options,
112+
follow: true, // TODO: This should be overridable by options.follow.
113+
});
114+
};
115+
94116
phpRuntime.FS.filesystems.NODEFS.node_ops.readlink = (
95117
node: any
96118
) => {

0 commit comments

Comments
 (0)