aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-wasm.c
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-08-13 13:56:00 +0000
committerstephan <stephan@noemail.net>2022-08-13 13:56:00 +0000
commit9a4c63b0fc85a019d3183abbd7939b081f45d025 (patch)
treec99980c7709d23ac40373a422066b1a1eaf9a3aa /ext/wasm/api/sqlite3-wasm.c
parent90218aec7a0991199b3e06faf723dd482bf970f6 (diff)
downloadsqlite-9a4c63b0fc85a019d3183abbd7939b081f45d025.tar.gz
sqlite-9a4c63b0fc85a019d3183abbd7939b081f45d025.zip
Cleanups in the wasmfs/opfs integration but disable it in order to get the build into a known-working state before continuing with experimentation.
FossilOrigin-Name: 41045be752a5bd7966849638f3ca56f4905308df70f79f2cb6196ca7dce9d525
Diffstat (limited to 'ext/wasm/api/sqlite3-wasm.c')
-rw-r--r--ext/wasm/api/sqlite3-wasm.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c
index 30a9dafeb..487baecf1 100644
--- a/ext/wasm/api/sqlite3-wasm.c
+++ b/ext/wasm/api/sqlite3-wasm.c
@@ -430,7 +430,7 @@ int sqlite3_wasm_vfs_unlink(const char * zName){
return rc;
}
-#ifdef __EMSCRIPTEN__
+#if defined(__EMSCRIPTEN__) && defined(SQLITE_WASM_OPFS)
#include <emscripten/wasmfs.h>
#include <emscripten/console.h>
/*
@@ -443,17 +443,34 @@ int sqlite3_wasm_vfs_unlink(const char * zName){
** WASMFS backend impl for OPFS. On success, subsequent calls are
** no-ops.
**
-** Returns 0 on success, SQLITE_NOMEM if intantiation of the backend
-** object fails.
+** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend
+** object fails, SQLITE_IOERR if mkdir() of the "/persistent" dir in
+** the virtual FS fails. In builds compiled without SQLITE_WASM_OPFS
+** defined, SQLITE_NOTFOUND is returned without side effects.
*/
int sqlite3_wasm_init_opfs(void){
static backend_t pOpfs = 0;
+ static const char * zDir = "/persistent";
if( !pOpfs ){
pOpfs = wasmfs_create_opfs_backend();
if( pOpfs ){
- emscripten_console_log("Created OPFS WASMFS backend.");
+ emscripten_console_log("Created WASMFS OPFS backend.");
}
}
+ /** It's not enough to instantiate the backend. We have to create a
+ mountpoint in the VFS and attach the backend to it. */
+ if( pOpfs && 0!=access(zDir, F_OK) ){
+ /* mkdir() simply hangs when called from fiddle app. Cause is
+ not yet determined but the hypothesis is an init-order
+ issue. */
+ const int rc = wasmfs_create_directory(zDir, 0777, pOpfs);
+ emscripten_console_log(rc ? "OPFS mkdir failed." : "OPFS mkdir ok.");
+ if(rc) return SQLITE_IOERR;
+ }
return pOpfs ? 0 : SQLITE_NOMEM;
}
-#endif /* __EMSCRIPTEN__ */
+#else
+int sqlite3_wasm_init_opfs(void){
+ return SQLITE_NOTFOUND;
+}
+#endif /* __EMSCRIPTEN__ && SQLITE_WASM_OPFS */