Skip to content

Commit d992361

Browse files
committed
Make FS proxying dependent on whether the FS is shared
1 parent 41a6f5c commit d992361

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

packages/php-wasm/universal/src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export {
7979
} from './urls';
8080

8181
export { isExitCode } from './is-exit-code';
82-
export { proxyFileSystem } from './proxy-file-system';
82+
export { proxyFileSystem, isPathToSharedFS } from './proxy-file-system';
8383
export { sandboxedSpawnHandlerFactory } from './sandboxed-spawn-handler-factory';
8484

8585
export * from './api';

packages/php-wasm/universal/src/lib/proxy-file-system.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,23 @@ export function proxyFileSystem(
3434
);
3535
}
3636
}
37+
38+
/**
39+
* Answers whether the given path is to a shared filesystem.
40+
*
41+
* @param sourceOfTruth - The PHP instance that is the source of truth.
42+
* @param path - The path to check.
43+
* @returns True if the path is to a shared filesystem, false otherwise.
44+
*/
45+
export function isPathToSharedFS(sourceOfTruth: PHP, path: string) {
46+
// We can't just import the symbol from the library because
47+
// Playground CLI is built as ESM and php-wasm-node is built as
48+
// CJS and the imported symbols will different in the production build.
49+
const __private__symbol = Object.getOwnPropertySymbols(sourceOfTruth)[0];
50+
51+
// @ts-ignore
52+
const FS = sourceOfTruth[__private__symbol].FS;
53+
54+
const fsResult = FS.lookupPath(path, { noent_okay: true });
55+
return fsResult?.node?.isSharedFS ?? false;
56+
}

packages/playground/wordpress/src/boot.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PHP,
1111
PHPRequestHandler,
1212
proxyFileSystem,
13+
isPathToSharedFS,
1314
rotatePHPRuntime,
1415
sandboxedSpawnHandlerFactory,
1516
setPhpIniEntries,
@@ -267,13 +268,23 @@ export async function bootRequestHandler(options: BootRequestHandlerOptions) {
267268
joinPaths(new URL(options.siteUrl).pathname, 'phpinfo.php')
268269
);
269270
} else {
270-
// Proxy the filesystem for all secondary PHP instances to
271-
// the primary one.
272-
proxyFileSystem(await requestHandler.getPrimaryPhp(), php, [
271+
const pathsToShareBetweenPhpInstances = [
273272
'/tmp',
274273
requestHandler.documentRoot,
275-
'/internal',
276-
]);
274+
'/internal/shared',
275+
'/internal/symlinks',
276+
];
277+
const pathsToProxy = pathsToShareBetweenPhpInstances.filter(
278+
(path) => !isPathToSharedFS(php, path)
279+
);
280+
281+
// Proxy the filesystem for all secondary PHP instances to
282+
// the primary one.
283+
proxyFileSystem(
284+
await requestHandler.getPrimaryPhp(),
285+
php,
286+
pathsToProxy
287+
);
277288
}
278289

279290
// Spawn handler is responsible for spawning processes for all the

0 commit comments

Comments
 (0)