@php-wasm/node 2.0.4 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/asyncify/7_2_34/php_7_2.wasm +0 -0
  2. package/asyncify/7_3_33/php_7_3.wasm +0 -0
  3. package/asyncify/7_4_33/php_7_4.wasm +0 -0
  4. package/asyncify/8_0_30/php_8_0.wasm +0 -0
  5. package/asyncify/8_1_33/php_8_1.wasm +0 -0
  6. package/asyncify/8_2_29/php_8_2.wasm +0 -0
  7. package/asyncify/8_3_23/php_8_3.wasm +0 -0
  8. package/asyncify/8_3_24/php_8_3.wasm +0 -0
  9. package/asyncify/8_4_10/php_8_4.wasm +0 -0
  10. package/asyncify/8_4_11/php_8_4.wasm +0 -0
  11. package/asyncify/php_7_2.js +512 -223
  12. package/asyncify/php_7_3.js +509 -220
  13. package/asyncify/php_7_4.js +516 -227
  14. package/asyncify/php_8_0.js +509 -220
  15. package/asyncify/php_8_1.js +509 -220
  16. package/asyncify/php_8_2.js +509 -220
  17. package/asyncify/php_8_3.js +519 -230
  18. package/asyncify/php_8_4.js +515 -226
  19. package/index.cjs +657 -1191
  20. package/index.js +657 -1191
  21. package/jspi/7_2_34/php_7_2.wasm +0 -0
  22. package/jspi/7_3_33/php_7_3.wasm +0 -0
  23. package/jspi/7_4_33/php_7_4.wasm +0 -0
  24. package/jspi/8_0_30/php_8_0.wasm +0 -0
  25. package/jspi/8_1_33/php_8_1.wasm +0 -0
  26. package/jspi/8_2_29/php_8_2.wasm +0 -0
  27. package/jspi/8_3_23/php_8_3.wasm +0 -0
  28. package/jspi/8_3_24/php_8_3.wasm +0 -0
  29. package/jspi/8_4_10/php_8_4.wasm +0 -0
  30. package/jspi/8_4_11/php_8_4.wasm +0 -0
  31. package/jspi/php_7_2.js +42 -36
  32. package/jspi/php_7_3.js +42 -36
  33. package/jspi/php_7_4.js +42 -36
  34. package/jspi/php_8_0.js +42 -36
  35. package/jspi/php_8_1.js +42 -36
  36. package/jspi/php_8_2.js +42 -36
  37. package/jspi/php_8_3.js +48 -42
  38. package/jspi/php_8_4.js +48 -42
  39. package/lib/file-lock-manager-for-node.d.ts +9 -2
  40. package/lib/load-runtime.d.ts +2 -1
  41. package/package.json +7 -7
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/jspi/php_7_2.js CHANGED
@@ -6994,35 +6994,25 @@ export function init(RuntimeName, PHPLoader) {
6994
6994
  1: 'exclusive',
6995
6995
  2: 'unlocked',
6996
6996
  },
6997
- is_shared_fs_node(node) {
6998
- if (node?.isSharedFS) {
6999
- return true;
7000
- }
7001
-
7002
- // Handle PROXYFS nodes which wrap other nodes.
7003
- if (
7004
- !node?.mount?.opts?.fs?.lookupPath ||
7005
- !node?.mount?.type?.realPath
7006
- ) {
7007
- return false;
6997
+ is_path_to_shared_fs(path) {
6998
+ _js_wasm_trace('is_path_to_shared_fs(%s)', path);
6999
+ const { node } = FS.lookupPath(path, { noent_okay: true });
7000
+ if (node.mount.type !== PROXYFS) {
7001
+ return !!node.isSharedFS;
7002
+ }
7003
+
7004
+ // This looks like a PROXYFS node. Let's try a lookup.
7005
+ const nodePath = PROXYFS.realPath(node);
7006
+ const backingFs = node?.mount?.opts?.fs;
7007
+ if (backingFs) {
7008
+ // Tolerate ENOENT because looking up a MEMFS node by path always fails.
7009
+ const { node: backingNode } = backingFs.lookupPath(nodePath, {
7010
+ noent_okay: true,
7011
+ });
7012
+ return !!backingNode?.isSharedFS;
7008
7013
  }
7009
7014
 
7010
- // Only NODEFS can be shared between workers at the moment.
7011
- if (node.mount.type !== NODEFS) {
7012
- return false;
7013
- }
7014
- const vfsPath = node.mount.type.realPath(node);
7015
- try {
7016
- const underlyingNode =
7017
- node.mount.opts.fs.lookupPath(vfsPath)?.node;
7018
- return !!underlyingNode?.isSharedFS;
7019
- } catch (e) {
7020
- return false;
7021
- }
7022
- },
7023
- is_path_to_shared_fs(path) {
7024
- const { node } = FS.lookupPath(path);
7025
- return locking.is_shared_fs_node(node);
7015
+ return false;
7026
7016
  },
7027
7017
  get_fd_access_mode(fd) {
7028
7018
  const emscripten_F_GETFL = Number('3');
@@ -7040,8 +7030,26 @@ export function init(RuntimeName, PHPLoader) {
7040
7030
  }
7041
7031
  },
7042
7032
  get_native_path_from_vfs_path(vfsPath) {
7043
- const { node } = FS.lookupPath(vfsPath);
7044
- return NODEFS.realPath(node);
7033
+ // TODO: Should there be a try/catch here?
7034
+ const { node } = FS.lookupPath(vfsPath, {});
7035
+ if (node.mount.type === NODEFS) {
7036
+ return NODEFS.realPath(node);
7037
+ } else if (node.mount.type === PROXYFS) {
7038
+ // TODO: Tolerate ENOENT here?
7039
+ const { node: backingNode, path: backingPath } =
7040
+ node.mount.opts.fs.lookupPath(vfsPath);
7041
+ _js_wasm_trace(
7042
+ 'backingNode for %s: %s',
7043
+ vfsPath,
7044
+ backingPath,
7045
+ backingNode
7046
+ );
7047
+ return backingNode.mount.type.realPath(backingNode);
7048
+ } else {
7049
+ throw new Error(
7050
+ `Unsupported filesystem type for path ${vfsPath}`
7051
+ );
7052
+ }
7045
7053
  },
7046
7054
  check_lock_params(fd, l_type) {
7047
7055
  const emscripten_O_RDONLY = Number('0');
@@ -7252,6 +7260,8 @@ export function init(RuntimeName, PHPLoader) {
7252
7260
  return -ERRNO_CODES.EBADF;
7253
7261
  }
7254
7262
 
7263
+ const flockStructAddr = syscallGetVarargP();
7264
+
7255
7265
  if (!locking.is_path_to_shared_fs(vfsPath)) {
7256
7266
  _js_wasm_trace(
7257
7267
  "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
@@ -7267,7 +7277,6 @@ export function init(RuntimeName, PHPLoader) {
7267
7277
  return 0;
7268
7278
  }
7269
7279
 
7270
- const flockStructAddr = syscallGetVarargP();
7271
7280
  const flockStruct = read_flock_struct(flockStructAddr);
7272
7281
 
7273
7282
  if (!(flockStruct.l_type in locking.fcntlToLockState)) {
@@ -34408,19 +34417,16 @@ export function init(RuntimeName, PHPLoader) {
34408
34417
  // We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
34409
34418
  // nodes. This way we can tell whether file-locking is needed and possible
34410
34419
  // for an FS node, even if wrapped with PROXYFS.
34411
- const originalCreateNode = NODEFS.createNode;
34420
+ const originalNodeFsCreateNode = NODEFS.createNode;
34412
34421
  NODEFS.createNode = function createNodeWithSharedFlag() {
34413
- const node = originalCreateNode.apply(NODEFS, arguments);
34422
+ const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
34414
34423
  node.isSharedFS = true;
34415
34424
  return node;
34416
34425
  };
34417
34426
 
34418
34427
  var originalHashAddNode = FS.hashAddNode;
34419
34428
  FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
34420
- if (
34421
- typeof locking === 'object' &&
34422
- locking?.is_shared_fs_node(node)
34423
- ) {
34429
+ if (node?.isSharedFS) {
34424
34430
  // Avoid caching shared VFS nodes so multiple instances
34425
34431
  // can access the same underlying filesystem without
34426
34432
  // conflicting caches.
package/jspi/php_7_3.js CHANGED
@@ -6994,35 +6994,25 @@ export function init(RuntimeName, PHPLoader) {
6994
6994
  1: 'exclusive',
6995
6995
  2: 'unlocked',
6996
6996
  },
6997
- is_shared_fs_node(node) {
6998
- if (node?.isSharedFS) {
6999
- return true;
7000
- }
7001
-
7002
- // Handle PROXYFS nodes which wrap other nodes.
7003
- if (
7004
- !node?.mount?.opts?.fs?.lookupPath ||
7005
- !node?.mount?.type?.realPath
7006
- ) {
7007
- return false;
6997
+ is_path_to_shared_fs(path) {
6998
+ _js_wasm_trace('is_path_to_shared_fs(%s)', path);
6999
+ const { node } = FS.lookupPath(path, { noent_okay: true });
7000
+ if (node.mount.type !== PROXYFS) {
7001
+ return !!node.isSharedFS;
7002
+ }
7003
+
7004
+ // This looks like a PROXYFS node. Let's try a lookup.
7005
+ const nodePath = PROXYFS.realPath(node);
7006
+ const backingFs = node?.mount?.opts?.fs;
7007
+ if (backingFs) {
7008
+ // Tolerate ENOENT because looking up a MEMFS node by path always fails.
7009
+ const { node: backingNode } = backingFs.lookupPath(nodePath, {
7010
+ noent_okay: true,
7011
+ });
7012
+ return !!backingNode?.isSharedFS;
7008
7013
  }
7009
7014
 
7010
- // Only NODEFS can be shared between workers at the moment.
7011
- if (node.mount.type !== NODEFS) {
7012
- return false;
7013
- }
7014
- const vfsPath = node.mount.type.realPath(node);
7015
- try {
7016
- const underlyingNode =
7017
- node.mount.opts.fs.lookupPath(vfsPath)?.node;
7018
- return !!underlyingNode?.isSharedFS;
7019
- } catch (e) {
7020
- return false;
7021
- }
7022
- },
7023
- is_path_to_shared_fs(path) {
7024
- const { node } = FS.lookupPath(path);
7025
- return locking.is_shared_fs_node(node);
7015
+ return false;
7026
7016
  },
7027
7017
  get_fd_access_mode(fd) {
7028
7018
  const emscripten_F_GETFL = Number('3');
@@ -7040,8 +7030,26 @@ export function init(RuntimeName, PHPLoader) {
7040
7030
  }
7041
7031
  },
7042
7032
  get_native_path_from_vfs_path(vfsPath) {
7043
- const { node } = FS.lookupPath(vfsPath);
7044
- return NODEFS.realPath(node);
7033
+ // TODO: Should there be a try/catch here?
7034
+ const { node } = FS.lookupPath(vfsPath, {});
7035
+ if (node.mount.type === NODEFS) {
7036
+ return NODEFS.realPath(node);
7037
+ } else if (node.mount.type === PROXYFS) {
7038
+ // TODO: Tolerate ENOENT here?
7039
+ const { node: backingNode, path: backingPath } =
7040
+ node.mount.opts.fs.lookupPath(vfsPath);
7041
+ _js_wasm_trace(
7042
+ 'backingNode for %s: %s',
7043
+ vfsPath,
7044
+ backingPath,
7045
+ backingNode
7046
+ );
7047
+ return backingNode.mount.type.realPath(backingNode);
7048
+ } else {
7049
+ throw new Error(
7050
+ `Unsupported filesystem type for path ${vfsPath}`
7051
+ );
7052
+ }
7045
7053
  },
7046
7054
  check_lock_params(fd, l_type) {
7047
7055
  const emscripten_O_RDONLY = Number('0');
@@ -7252,6 +7260,8 @@ export function init(RuntimeName, PHPLoader) {
7252
7260
  return -ERRNO_CODES.EBADF;
7253
7261
  }
7254
7262
 
7263
+ const flockStructAddr = syscallGetVarargP();
7264
+
7255
7265
  if (!locking.is_path_to_shared_fs(vfsPath)) {
7256
7266
  _js_wasm_trace(
7257
7267
  "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
@@ -7267,7 +7277,6 @@ export function init(RuntimeName, PHPLoader) {
7267
7277
  return 0;
7268
7278
  }
7269
7279
 
7270
- const flockStructAddr = syscallGetVarargP();
7271
7280
  const flockStruct = read_flock_struct(flockStructAddr);
7272
7281
 
7273
7282
  if (!(flockStruct.l_type in locking.fcntlToLockState)) {
@@ -34408,19 +34417,16 @@ export function init(RuntimeName, PHPLoader) {
34408
34417
  // We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
34409
34418
  // nodes. This way we can tell whether file-locking is needed and possible
34410
34419
  // for an FS node, even if wrapped with PROXYFS.
34411
- const originalCreateNode = NODEFS.createNode;
34420
+ const originalNodeFsCreateNode = NODEFS.createNode;
34412
34421
  NODEFS.createNode = function createNodeWithSharedFlag() {
34413
- const node = originalCreateNode.apply(NODEFS, arguments);
34422
+ const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
34414
34423
  node.isSharedFS = true;
34415
34424
  return node;
34416
34425
  };
34417
34426
 
34418
34427
  var originalHashAddNode = FS.hashAddNode;
34419
34428
  FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
34420
- if (
34421
- typeof locking === 'object' &&
34422
- locking?.is_shared_fs_node(node)
34423
- ) {
34429
+ if (node?.isSharedFS) {
34424
34430
  // Avoid caching shared VFS nodes so multiple instances
34425
34431
  // can access the same underlying filesystem without
34426
34432
  // conflicting caches.
package/jspi/php_7_4.js CHANGED
@@ -6994,35 +6994,25 @@ export function init(RuntimeName, PHPLoader) {
6994
6994
  1: 'exclusive',
6995
6995
  2: 'unlocked',
6996
6996
  },
6997
- is_shared_fs_node(node) {
6998
- if (node?.isSharedFS) {
6999
- return true;
7000
- }
7001
-
7002
- // Handle PROXYFS nodes which wrap other nodes.
7003
- if (
7004
- !node?.mount?.opts?.fs?.lookupPath ||
7005
- !node?.mount?.type?.realPath
7006
- ) {
7007
- return false;
6997
+ is_path_to_shared_fs(path) {
6998
+ _js_wasm_trace('is_path_to_shared_fs(%s)', path);
6999
+ const { node } = FS.lookupPath(path, { noent_okay: true });
7000
+ if (node.mount.type !== PROXYFS) {
7001
+ return !!node.isSharedFS;
7002
+ }
7003
+
7004
+ // This looks like a PROXYFS node. Let's try a lookup.
7005
+ const nodePath = PROXYFS.realPath(node);
7006
+ const backingFs = node?.mount?.opts?.fs;
7007
+ if (backingFs) {
7008
+ // Tolerate ENOENT because looking up a MEMFS node by path always fails.
7009
+ const { node: backingNode } = backingFs.lookupPath(nodePath, {
7010
+ noent_okay: true,
7011
+ });
7012
+ return !!backingNode?.isSharedFS;
7008
7013
  }
7009
7014
 
7010
- // Only NODEFS can be shared between workers at the moment.
7011
- if (node.mount.type !== NODEFS) {
7012
- return false;
7013
- }
7014
- const vfsPath = node.mount.type.realPath(node);
7015
- try {
7016
- const underlyingNode =
7017
- node.mount.opts.fs.lookupPath(vfsPath)?.node;
7018
- return !!underlyingNode?.isSharedFS;
7019
- } catch (e) {
7020
- return false;
7021
- }
7022
- },
7023
- is_path_to_shared_fs(path) {
7024
- const { node } = FS.lookupPath(path);
7025
- return locking.is_shared_fs_node(node);
7015
+ return false;
7026
7016
  },
7027
7017
  get_fd_access_mode(fd) {
7028
7018
  const emscripten_F_GETFL = Number('3');
@@ -7040,8 +7030,26 @@ export function init(RuntimeName, PHPLoader) {
7040
7030
  }
7041
7031
  },
7042
7032
  get_native_path_from_vfs_path(vfsPath) {
7043
- const { node } = FS.lookupPath(vfsPath);
7044
- return NODEFS.realPath(node);
7033
+ // TODO: Should there be a try/catch here?
7034
+ const { node } = FS.lookupPath(vfsPath, {});
7035
+ if (node.mount.type === NODEFS) {
7036
+ return NODEFS.realPath(node);
7037
+ } else if (node.mount.type === PROXYFS) {
7038
+ // TODO: Tolerate ENOENT here?
7039
+ const { node: backingNode, path: backingPath } =
7040
+ node.mount.opts.fs.lookupPath(vfsPath);
7041
+ _js_wasm_trace(
7042
+ 'backingNode for %s: %s',
7043
+ vfsPath,
7044
+ backingPath,
7045
+ backingNode
7046
+ );
7047
+ return backingNode.mount.type.realPath(backingNode);
7048
+ } else {
7049
+ throw new Error(
7050
+ `Unsupported filesystem type for path ${vfsPath}`
7051
+ );
7052
+ }
7045
7053
  },
7046
7054
  check_lock_params(fd, l_type) {
7047
7055
  const emscripten_O_RDONLY = Number('0');
@@ -7252,6 +7260,8 @@ export function init(RuntimeName, PHPLoader) {
7252
7260
  return -ERRNO_CODES.EBADF;
7253
7261
  }
7254
7262
 
7263
+ const flockStructAddr = syscallGetVarargP();
7264
+
7255
7265
  if (!locking.is_path_to_shared_fs(vfsPath)) {
7256
7266
  _js_wasm_trace(
7257
7267
  "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
@@ -7267,7 +7277,6 @@ export function init(RuntimeName, PHPLoader) {
7267
7277
  return 0;
7268
7278
  }
7269
7279
 
7270
- const flockStructAddr = syscallGetVarargP();
7271
7280
  const flockStruct = read_flock_struct(flockStructAddr);
7272
7281
 
7273
7282
  if (!(flockStruct.l_type in locking.fcntlToLockState)) {
@@ -34408,19 +34417,16 @@ export function init(RuntimeName, PHPLoader) {
34408
34417
  // We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
34409
34418
  // nodes. This way we can tell whether file-locking is needed and possible
34410
34419
  // for an FS node, even if wrapped with PROXYFS.
34411
- const originalCreateNode = NODEFS.createNode;
34420
+ const originalNodeFsCreateNode = NODEFS.createNode;
34412
34421
  NODEFS.createNode = function createNodeWithSharedFlag() {
34413
- const node = originalCreateNode.apply(NODEFS, arguments);
34422
+ const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
34414
34423
  node.isSharedFS = true;
34415
34424
  return node;
34416
34425
  };
34417
34426
 
34418
34427
  var originalHashAddNode = FS.hashAddNode;
34419
34428
  FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
34420
- if (
34421
- typeof locking === 'object' &&
34422
- locking?.is_shared_fs_node(node)
34423
- ) {
34429
+ if (node?.isSharedFS) {
34424
34430
  // Avoid caching shared VFS nodes so multiple instances
34425
34431
  // can access the same underlying filesystem without
34426
34432
  // conflicting caches.
package/jspi/php_8_0.js CHANGED
@@ -6994,35 +6994,25 @@ export function init(RuntimeName, PHPLoader) {
6994
6994
  1: 'exclusive',
6995
6995
  2: 'unlocked',
6996
6996
  },
6997
- is_shared_fs_node(node) {
6998
- if (node?.isSharedFS) {
6999
- return true;
7000
- }
7001
-
7002
- // Handle PROXYFS nodes which wrap other nodes.
7003
- if (
7004
- !node?.mount?.opts?.fs?.lookupPath ||
7005
- !node?.mount?.type?.realPath
7006
- ) {
7007
- return false;
6997
+ is_path_to_shared_fs(path) {
6998
+ _js_wasm_trace('is_path_to_shared_fs(%s)', path);
6999
+ const { node } = FS.lookupPath(path, { noent_okay: true });
7000
+ if (node.mount.type !== PROXYFS) {
7001
+ return !!node.isSharedFS;
7002
+ }
7003
+
7004
+ // This looks like a PROXYFS node. Let's try a lookup.
7005
+ const nodePath = PROXYFS.realPath(node);
7006
+ const backingFs = node?.mount?.opts?.fs;
7007
+ if (backingFs) {
7008
+ // Tolerate ENOENT because looking up a MEMFS node by path always fails.
7009
+ const { node: backingNode } = backingFs.lookupPath(nodePath, {
7010
+ noent_okay: true,
7011
+ });
7012
+ return !!backingNode?.isSharedFS;
7008
7013
  }
7009
7014
 
7010
- // Only NODEFS can be shared between workers at the moment.
7011
- if (node.mount.type !== NODEFS) {
7012
- return false;
7013
- }
7014
- const vfsPath = node.mount.type.realPath(node);
7015
- try {
7016
- const underlyingNode =
7017
- node.mount.opts.fs.lookupPath(vfsPath)?.node;
7018
- return !!underlyingNode?.isSharedFS;
7019
- } catch (e) {
7020
- return false;
7021
- }
7022
- },
7023
- is_path_to_shared_fs(path) {
7024
- const { node } = FS.lookupPath(path);
7025
- return locking.is_shared_fs_node(node);
7015
+ return false;
7026
7016
  },
7027
7017
  get_fd_access_mode(fd) {
7028
7018
  const emscripten_F_GETFL = Number('3');
@@ -7040,8 +7030,26 @@ export function init(RuntimeName, PHPLoader) {
7040
7030
  }
7041
7031
  },
7042
7032
  get_native_path_from_vfs_path(vfsPath) {
7043
- const { node } = FS.lookupPath(vfsPath);
7044
- return NODEFS.realPath(node);
7033
+ // TODO: Should there be a try/catch here?
7034
+ const { node } = FS.lookupPath(vfsPath, {});
7035
+ if (node.mount.type === NODEFS) {
7036
+ return NODEFS.realPath(node);
7037
+ } else if (node.mount.type === PROXYFS) {
7038
+ // TODO: Tolerate ENOENT here?
7039
+ const { node: backingNode, path: backingPath } =
7040
+ node.mount.opts.fs.lookupPath(vfsPath);
7041
+ _js_wasm_trace(
7042
+ 'backingNode for %s: %s',
7043
+ vfsPath,
7044
+ backingPath,
7045
+ backingNode
7046
+ );
7047
+ return backingNode.mount.type.realPath(backingNode);
7048
+ } else {
7049
+ throw new Error(
7050
+ `Unsupported filesystem type for path ${vfsPath}`
7051
+ );
7052
+ }
7045
7053
  },
7046
7054
  check_lock_params(fd, l_type) {
7047
7055
  const emscripten_O_RDONLY = Number('0');
@@ -7252,6 +7260,8 @@ export function init(RuntimeName, PHPLoader) {
7252
7260
  return -ERRNO_CODES.EBADF;
7253
7261
  }
7254
7262
 
7263
+ const flockStructAddr = syscallGetVarargP();
7264
+
7255
7265
  if (!locking.is_path_to_shared_fs(vfsPath)) {
7256
7266
  _js_wasm_trace(
7257
7267
  "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
@@ -7267,7 +7277,6 @@ export function init(RuntimeName, PHPLoader) {
7267
7277
  return 0;
7268
7278
  }
7269
7279
 
7270
- const flockStructAddr = syscallGetVarargP();
7271
7280
  const flockStruct = read_flock_struct(flockStructAddr);
7272
7281
 
7273
7282
  if (!(flockStruct.l_type in locking.fcntlToLockState)) {
@@ -34408,19 +34417,16 @@ export function init(RuntimeName, PHPLoader) {
34408
34417
  // We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
34409
34418
  // nodes. This way we can tell whether file-locking is needed and possible
34410
34419
  // for an FS node, even if wrapped with PROXYFS.
34411
- const originalCreateNode = NODEFS.createNode;
34420
+ const originalNodeFsCreateNode = NODEFS.createNode;
34412
34421
  NODEFS.createNode = function createNodeWithSharedFlag() {
34413
- const node = originalCreateNode.apply(NODEFS, arguments);
34422
+ const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
34414
34423
  node.isSharedFS = true;
34415
34424
  return node;
34416
34425
  };
34417
34426
 
34418
34427
  var originalHashAddNode = FS.hashAddNode;
34419
34428
  FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
34420
- if (
34421
- typeof locking === 'object' &&
34422
- locking?.is_shared_fs_node(node)
34423
- ) {
34429
+ if (node?.isSharedFS) {
34424
34430
  // Avoid caching shared VFS nodes so multiple instances
34425
34431
  // can access the same underlying filesystem without
34426
34432
  // conflicting caches.
package/jspi/php_8_1.js CHANGED
@@ -6994,35 +6994,25 @@ export function init(RuntimeName, PHPLoader) {
6994
6994
  1: 'exclusive',
6995
6995
  2: 'unlocked',
6996
6996
  },
6997
- is_shared_fs_node(node) {
6998
- if (node?.isSharedFS) {
6999
- return true;
7000
- }
7001
-
7002
- // Handle PROXYFS nodes which wrap other nodes.
7003
- if (
7004
- !node?.mount?.opts?.fs?.lookupPath ||
7005
- !node?.mount?.type?.realPath
7006
- ) {
7007
- return false;
6997
+ is_path_to_shared_fs(path) {
6998
+ _js_wasm_trace('is_path_to_shared_fs(%s)', path);
6999
+ const { node } = FS.lookupPath(path, { noent_okay: true });
7000
+ if (node.mount.type !== PROXYFS) {
7001
+ return !!node.isSharedFS;
7002
+ }
7003
+
7004
+ // This looks like a PROXYFS node. Let's try a lookup.
7005
+ const nodePath = PROXYFS.realPath(node);
7006
+ const backingFs = node?.mount?.opts?.fs;
7007
+ if (backingFs) {
7008
+ // Tolerate ENOENT because looking up a MEMFS node by path always fails.
7009
+ const { node: backingNode } = backingFs.lookupPath(nodePath, {
7010
+ noent_okay: true,
7011
+ });
7012
+ return !!backingNode?.isSharedFS;
7008
7013
  }
7009
7014
 
7010
- // Only NODEFS can be shared between workers at the moment.
7011
- if (node.mount.type !== NODEFS) {
7012
- return false;
7013
- }
7014
- const vfsPath = node.mount.type.realPath(node);
7015
- try {
7016
- const underlyingNode =
7017
- node.mount.opts.fs.lookupPath(vfsPath)?.node;
7018
- return !!underlyingNode?.isSharedFS;
7019
- } catch (e) {
7020
- return false;
7021
- }
7022
- },
7023
- is_path_to_shared_fs(path) {
7024
- const { node } = FS.lookupPath(path);
7025
- return locking.is_shared_fs_node(node);
7015
+ return false;
7026
7016
  },
7027
7017
  get_fd_access_mode(fd) {
7028
7018
  const emscripten_F_GETFL = Number('3');
@@ -7040,8 +7030,26 @@ export function init(RuntimeName, PHPLoader) {
7040
7030
  }
7041
7031
  },
7042
7032
  get_native_path_from_vfs_path(vfsPath) {
7043
- const { node } = FS.lookupPath(vfsPath);
7044
- return NODEFS.realPath(node);
7033
+ // TODO: Should there be a try/catch here?
7034
+ const { node } = FS.lookupPath(vfsPath, {});
7035
+ if (node.mount.type === NODEFS) {
7036
+ return NODEFS.realPath(node);
7037
+ } else if (node.mount.type === PROXYFS) {
7038
+ // TODO: Tolerate ENOENT here?
7039
+ const { node: backingNode, path: backingPath } =
7040
+ node.mount.opts.fs.lookupPath(vfsPath);
7041
+ _js_wasm_trace(
7042
+ 'backingNode for %s: %s',
7043
+ vfsPath,
7044
+ backingPath,
7045
+ backingNode
7046
+ );
7047
+ return backingNode.mount.type.realPath(backingNode);
7048
+ } else {
7049
+ throw new Error(
7050
+ `Unsupported filesystem type for path ${vfsPath}`
7051
+ );
7052
+ }
7045
7053
  },
7046
7054
  check_lock_params(fd, l_type) {
7047
7055
  const emscripten_O_RDONLY = Number('0');
@@ -7252,6 +7260,8 @@ export function init(RuntimeName, PHPLoader) {
7252
7260
  return -ERRNO_CODES.EBADF;
7253
7261
  }
7254
7262
 
7263
+ const flockStructAddr = syscallGetVarargP();
7264
+
7255
7265
  if (!locking.is_path_to_shared_fs(vfsPath)) {
7256
7266
  _js_wasm_trace(
7257
7267
  "fcntl(%d, F_GETLK) locking is not implemented for non-NodeFS path '%s'",
@@ -7267,7 +7277,6 @@ export function init(RuntimeName, PHPLoader) {
7267
7277
  return 0;
7268
7278
  }
7269
7279
 
7270
- const flockStructAddr = syscallGetVarargP();
7271
7280
  const flockStruct = read_flock_struct(flockStructAddr);
7272
7281
 
7273
7282
  if (!(flockStruct.l_type in locking.fcntlToLockState)) {
@@ -34408,19 +34417,16 @@ export function init(RuntimeName, PHPLoader) {
34408
34417
  // We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
34409
34418
  // nodes. This way we can tell whether file-locking is needed and possible
34410
34419
  // for an FS node, even if wrapped with PROXYFS.
34411
- const originalCreateNode = NODEFS.createNode;
34420
+ const originalNodeFsCreateNode = NODEFS.createNode;
34412
34421
  NODEFS.createNode = function createNodeWithSharedFlag() {
34413
- const node = originalCreateNode.apply(NODEFS, arguments);
34422
+ const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
34414
34423
  node.isSharedFS = true;
34415
34424
  return node;
34416
34425
  };
34417
34426
 
34418
34427
  var originalHashAddNode = FS.hashAddNode;
34419
34428
  FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
34420
- if (
34421
- typeof locking === 'object' &&
34422
- locking?.is_shared_fs_node(node)
34423
- ) {
34429
+ if (node?.isSharedFS) {
34424
34430
  // Avoid caching shared VFS nodes so multiple instances
34425
34431
  // can access the same underlying filesystem without
34426
34432
  // conflicting caches.