Skip to content

Commit deb9f85

Browse files
committed
Create mount point only if lookup throws error ENOENT
1 parent 6a42ec1 commit deb9f85

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MountHandler } from '@php-wasm/universal';
1+
import type { ErrnoError, MountHandler } from '@php-wasm/universal';
22
import { statSync } from 'fs';
33
import { dirname } from 'path';
44

@@ -21,7 +21,11 @@ export function createNodeFsMountHandler(localPath: string): MountHandler {
2121
try {
2222
lookup = FS.lookupPath(vfsMountPoint);
2323
} catch (e) {
24-
// FS.lookupPath will throw an error if the path doesn't exist.
24+
const err = e as ErrnoError;
25+
// FS.lookupPath will throw an error with errno 44 if the path doesn't exist.
26+
if (err.errno !== 44) {
27+
throw e;
28+
}
2529
if (statSync(localPath).isFile()) {
2630
FS.writeFile(vfsMountPoint, '');
2731
} else if (statSync(localPath).isDirectory()) {

packages/php-wasm/node/src/test/mounting.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createNodeFsMountHandler, loadNodeRuntime } from '..';
2-
import { __private__dont__use, PHP } from '@php-wasm/universal';
2+
import { PHP } from '@php-wasm/universal';
33
import { RecommendedPHPVersion } from '@wp-playground/common';
44
import path from 'path';
55
import fs from 'fs';

0 commit comments

Comments
 (0)