Skip to content

Commit 4726892

Browse files
Fix file locking for PROXYFS nodes that wrap NODEFS (#2437)
## Motivation for the change, related issues File locking isn't applying to SQLite DB when a real directory is mounted as `/wordpress`. It looks like this happens for PROXYFS nodes that wrap NODEFS nodes. Fixes #2427 ## Implementation details This PR fixes PROXYFS lookups of original NODEFS nodes so we can check whether a node is for a shared FS or for MEMFS. This PR also fills in two unimplemented FileLockManagerForNode tests and adds them to the `test-asyncify` and `test-jspi` targets for the php-wasm-node project. While fixing the tests, I noticed a couple of whole-file locking where locks were allowed where macOS's locking implementation would have denied them (fcntl() and flock() locks held by the same process can conflict). IIUC, Linux may not deny locks in those cases, but I've tried to lean toward being more restrictive rather than more permissive when it comes to granting locks. ## Testing Instructions (or ideally a Blueprint) - New unit tests that test file locking behavior for proxied and unproxied NODEFS and MEMFS nodes.
1 parent 3d9f41c commit 4726892

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1073
-649
lines changed

packages/php-wasm/compile/php/esm-suffix.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,16 @@ if (typeof NODEFS === 'object') {
6060
// We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
6161
// nodes. This way we can tell whether file-locking is needed and possible
6262
// for an FS node, even if wrapped with PROXYFS.
63-
const originalCreateNode = NODEFS.createNode;
63+
const originalNodeFsCreateNode = NODEFS.createNode;
6464
NODEFS.createNode = function createNodeWithSharedFlag() {
65-
const node = originalCreateNode.apply(NODEFS, arguments);
65+
const node = originalNodeFsCreateNode.apply(NODEFS, arguments);
6666
node.isSharedFS = true;
6767
return node;
6868
};
6969

7070
var originalHashAddNode = FS.hashAddNode;
7171
FS.hashAddNode = function hashAddNodeIfNotSharedFS(node) {
72-
if (
73-
typeof locking === 'object' &&
74-
locking?.is_shared_fs_node(node)
75-
) {
72+
if (node?.isSharedFS) {
7673
// Avoid caching shared VFS nodes so multiple instances
7774
// can access the same underlying filesystem without
7875
// conflicting caches.

0 commit comments

Comments
 (0)