Skip to content

Commit 78586c3

Browse files
committed
Fix IDBFS not auto-persisting on directory creation
FS.mkdir does not use mkdir under the hood but rather mknod. The patched version of mknod installed by IDBFS only invokes IDBFS.queuePersist() when the node's stream is closed, which never happens for mkdir as the handle is immediately discarded and no stream is ever created. Furthermore, the bare fact of file/directory creation should be persisted even if no writes are made to the node. The test doesn't catch this because reconcilation happens in a JavaScript task, and no tasks or microtasks can execute while code is executing. IDBFS.syncfs only has a chance to run after the entirety of the test function finishes executing, at which point all of file/directory operations have been executed and persisted in memory. As long as one of those operations calls IDBFS.queuePersist, it ensures that the whole memory filesystem will get persisted to IDB and therefore shadows missing calls to IDBFS.queuePersist in other operations. Remove the mkdir node op patching (which has never been a real node op) and make mknod queue a persist operation as soon as the node is created without waiting for the caller to interact with a stream.
1 parent 052cd1a commit 78586c3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/libidbfs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ addToLibrary({
8585
if (n.memfs_stream_ops.close) return n.memfs_stream_ops.close(stream);
8686
};
8787

88+
// Persist the node we just created to IndexedDB
89+
IDBFS.queuePersist(mnt.mount);
90+
8891
return node;
8992
};
9093
// Also kick off persisting the filesystem on other operations that modify the filesystem.
91-
mnt.node_ops.mkdir = (...args) => (IDBFS.queuePersist(mnt.mount), memfs_node_ops.mkdir(...args));
9294
mnt.node_ops.rmdir = (...args) => (IDBFS.queuePersist(mnt.mount), memfs_node_ops.rmdir(...args));
9395
mnt.node_ops.symlink = (...args) => (IDBFS.queuePersist(mnt.mount), memfs_node_ops.symlink(...args));
9496
mnt.node_ops.unlink = (...args) => (IDBFS.queuePersist(mnt.mount), memfs_node_ops.unlink(...args));

0 commit comments

Comments
 (0)