-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: respect access mode and file open flags #1962
base: main
Are you sure you want to change the base?
Conversation
console.debug(`File ${path} does not exists yet, creating...`); | ||
return dirHandle.getFileHandle(fileName, { create: true }); | ||
} | ||
console.debug(`File ${path} does not exists, aborting as we are in read-only mode`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Five lines below this, where we call createSyncAccessHandle, we can pass a new optional mode to OPFS to further enforce the access mode: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle#mode
If the access mode is passed to createSyncAccessHandle, it would allow read-only connections to be opened simultaneously (for example when using the same app in multiple tabs). A big win for duckdb-wasm + OPFS.
The option is only implemented in Chrome and Edge right now, but issues exist to implement in both Webkit and Firefox:
https://bugs.webkit.org/show_bug.cgi?id=283959
https://bugzilla.mozilla.org/show_bug.cgi?id=1949462
And tests have already been added to the Web Platform Tests dashboard:
https://wpt.fyi/results/fs/FileSystemFileHandle-sync-access-handle-lock-modes.https.tentative.worker.html?label=experimental&label=master&aligned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amiller-gh
I believe it's fine for this PR to focus only on a single window.
I think we should first handle single-window support before addressing multiple windows.
Because the mode argument of the createSyncAccessHandle method was introduced to specify the file access mode. However, this argument has not yet been enabled in lib.webworker.d.ts (the Web Worker type definition file). As a result, using this argument in TypeScript may cause a type error. To resolve this issue, you need to either wait for the type definition file to be updated or extend the type definitions within your project.
And, I plan to create a PR for handling multiple windows, so this PR needs to be merged for that.
@sumimakito Because the mode argument of the createSyncAccessHandle method was introduced to specify the file access mode. However, this argument has not yet been enabled in lib.webworker.d.ts (the Web Worker type definition file). As a result, using this argument in TypeScript may cause a type error. To resolve this issue, you need to either wait for the type definition file to be updated or extend the type definitions within your project. And, I plan to create a PR for handling multiple windows, so this PR needs to be merged for that. |
Previous PR: #1960 (it can be closed if this PR looks better as this PR addresses more issues for both OPFS and Node FS)
Summary
accessMode
indb.open(...)
will be respected and empty database files (and directories in OPFS) will no longer be created in the read-only modeopenFile
in the Node runtime as it should returnnullptr
when the file does not exist and theFILE_FLAGS_NULL_IF_NOT_EXISTS
is setFileFlags
to the JavaScript bindingssrc/storage/storage_manager.cpp
in theduckdb
submodule