diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 486d1396d8..b6d81c00fc 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -376,7 +376,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js sqlite3-api.jses += $(dir.api)/sqlite3-v-helper.js sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js -sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.js +sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js # SOAP.js is an external API file which is part of our distribution diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md index be53ac25aa..eb0f073cf7 100644 --- a/ext/wasm/api/README.md +++ b/ext/wasm/api/README.md @@ -91,7 +91,7 @@ browser client: directly to the (async) OPFS API and channels those results back to its synchronous counterpart. This file, because it must be started in its own Worker, is not part of the amalgamation. -- **`sqlite3-vfs-opfs-sahpool.js`**\ +- **`sqlite3-vfs-opfs-sahpool.c-pp.js`**\ is another sqlite3 VFS supporting the OPFS, but uses a completely different approach that the above-listed one. - **`sqlite3-api-cleanup.js`**\ @@ -111,13 +111,15 @@ browser client: with `c-pp`](#c-pp), noting that such preprocessing may be applied after all of the relevant files are concatenated. That extension is used primarily to keep the code maintainers cognisant of the fact that -those files contain constructs which will not run as-is in JavaScript. +those files contain constructs which may not run as-is in any given +JavaScript environment. The build process glues those files together, resulting in -`sqlite3-api.js`, which is everything except for the `post-js-*.js` -files, and `sqlite3.js`, which is the Emscripten-generated amalgamated -output and includes the `post-js-*.js` parts, as well as the -Emscripten-provided module loading pieces. +`sqlite3-api.js`, which is everything except for the +`pre/post-js-*.js` files, and `sqlite3.js`, which is the +Emscripten-generated amalgamated output and includes the +`pre/post-js-*.js` parts, as well as the Emscripten-provided module +loading pieces. The non-JS outlier file is `sqlite3-wasm.c`: it is a proxy for `sqlite3.c` which `#include`'s that file and adds a couple more diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js similarity index 96% rename from ext/wasm/api/sqlite3-vfs-opfs-sahpool.js rename to ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js index f34c87004d..8a129d60f2 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.js +++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js @@ -1,3 +1,4 @@ +//#ifnot target=node /* 2023-07-14 @@ -52,8 +53,8 @@ major browsers released since March 2023). If that API is not detected, the VFS is not registered. */ -'use strict'; globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ + 'use strict'; const toss = sqlite3.util.toss; const toss3 = sqlite3.util.toss3; const initPromises = Object.create(null); @@ -79,6 +80,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ capi.SQLITE_OPEN_WAL /* noting that WAL support is unavailable in the WASM build.*/; + /** Subdirectory of the VFS's space where "opaque" (randomly-named) + files are stored. Changing this effectively invalidates the data + stored under older names (orphaning it), so don't do that. */ + const OPAQUE_DIR_NAME = ".opaque"; + /** Returns short a string of random alphanumeric characters suitable for use as a random filename. @@ -423,6 +429,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ vfsDir; /* Directory handle to this.vfsDir. */ #dhVfsRoot; + /* Directory handle to the subdir of this.#dhVfsRoot which holds + the randomly-named "opaque" files. This subdir exists in the + hope that we can eventually support client-created files in + this.#dhVfsRoot. */ + #dhOpaque; /* Directory handle to this.dhVfsRoot's parent dir. Needed for a VFS-wipe op. */ #dhVfsParent; @@ -447,11 +458,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ #verbosity; constructor(options = Object.create(null)){ + this.#verbosity = options.verbosity ?? optionDefaults.verbosity; this.vfsName = options.name || optionDefaults.name; if( sqlite3.capi.sqlite3_vfs_find(this.vfsName)){ toss3("VFS name is already registered:", this.vfsName); } - this.#verbosity = options.verbosity ?? optionDefaults.verbosity; this.#cVfs = createOpfsVfs(this.vfsName); setPoolForVfs(this.#cVfs.pointer, this); this.vfsDir = options.directory || ("."+this.vfsName); @@ -491,7 +502,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ async addCapacity(n){ for(let i = 0; i < n; ++i){ const name = getRandomName(); - const h = await this.#dhVfsRoot.getFileHandle(name, {create:true}); + const h = await this.#dhOpaque.getFileHandle(name, {create:true}); const ah = await h.createSyncAccessHandle(); this.#mapSAHToName.set(ah,name); this.setAssociatedPath(ah, '', 0); @@ -512,7 +523,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } const name = this.#mapSAHToName.get(ah); ah.close(); - await this.#dhVfsRoot.removeEntry(name); + await this.#dhOpaque.removeEntry(name); this.#mapSAHToName.delete(ah); this.#availableSAH.delete(ah); ++nRm; @@ -532,7 +543,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } /** - Opens all files under this.vfsDir/this.#dhVfsRoot and acquires + Opens all files under this.vfsDir/this.#dhOpaque and acquires a SAH for each. returns a Promise which resolves to no value but completes once all SAHs are acquired. If acquiring an SAH throws, SAHPool.$error will contain the corresponding @@ -544,7 +555,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ async acquireAccessHandles(clearFiles){ const files = []; - for await (const [name,h] of this.#dhVfsRoot){ + for await (const [name,h] of this.#dhOpaque){ if('file'===h.kind){ files.push([name,h]); } @@ -680,6 +691,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } this.#dhVfsRoot = h; this.#dhVfsParent = prev; + this.#dhOpaque = await this.#dhVfsRoot.getDirectoryHandle( + OPAQUE_DIR_NAME,{create:true} + ); this.releaseAccessHandles(); return this.acquireAccessHandles(clearFiles); } @@ -691,6 +705,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - a URL object - A JS string representing a file name - Wasm C-string representing a file name + + All "../" parts and duplicate slashes are resolve/removed from + the returned result. */ getPath(arg) { if(wasm.isPtr(arg)) arg = wasm.cstrToJs(arg); @@ -790,17 +807,17 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ VFS has already been shut down. */ async removeVfs(){ - if(!this.#cVfs.pointer) return false; + if(!this.#cVfs.pointer || !this.#dhOpaque) return false; capi.sqlite3_vfs_unregister(this.#cVfs.pointer); this.#cVfs.dispose(); try{ this.releaseAccessHandles(); - if(this.#dhVfsParent){ - await this.#dhVfsParent.removeEntry( - this.#dhVfsRoot.name, {recursive: true} - ); - this.#dhVfsRoot = this.#dhVfsParent = undefined; - } + await this.#dhVfsRoot.removeEntry(OPAQUE_DIR_NAME, {recursive: true}); + this.#dhOpaque = undefined; + await this.#dhVfsParent.removeEntry( + this.#dhVfsRoot.name, {recursive: true} + ); + this.#dhVfsRoot = this.#dhVfsParent = undefined; }catch(e){ sqlite3.config.error(this.vfsName,"removeVfs() failed:",e); /*otherwise ignored - there is no recovery strategy*/ @@ -1120,7 +1137,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** The poolUtil object will be the result of the resolved Promise. */ const poolUtil = new OpfsSAHPoolUtil(thePool); - if(sqlite3.oo1){ const oo1 = sqlite3.oo1; const theVfs = thePool.getVfs(); @@ -1130,12 +1146,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ oo1.DB.dbCtorHelper.call(this, opt); }; OpfsSAHPoolDb.prototype = Object.create(oo1.DB.prototype); - OpfsSAHPoolDb.PoolUtil = poolUtil; - if(!oo1.OpfsSAHPool){ - oo1.OpfsSAHPool = Object.create(null); - oo1.OpfsSAHPool.default = OpfsSAHPoolDb; - } - oo1.OpfsSAHPool[vfsName] = OpfsSAHPoolDb; + // yes or no? OpfsSAHPoolDb.PoolUtil = poolUtil; + poolUtil.OpfsSAHPoolDb = OpfsSAHPoolDb; oo1.DB.dbCtorHelper.setVfsPostOpenSql( theVfs.pointer, function(oo1Db, sqlite3){ @@ -1159,3 +1171,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }); }/*installOpfsSAHPoolVfs()*/; }/*sqlite3ApiBootstrap.initializers*/); +//#else +/* + The OPFS SAH Pool VFS parts are elided from builds targeting + node.js. +*/ +//#endif target=node diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 7d313a2635..61b7534de7 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -1,3 +1,4 @@ +//#ifnot target=node /* 2022-09-18 @@ -1370,3 +1371,6 @@ globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{ } }); }/*sqlite3ApiBootstrap.initializers.push()*/); +//#else +/* The OPFS VFS parts are elided from builds targeting node.js. */ +//#endif target=node diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 56a4369cd5..905340b234 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3054,16 +3054,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule; run. */) .assert(u1.getCapacity() + 2 === (await u2.addCapacity(2))) .assert(2 === (await u2.reduceCapacity(2))) - .assert(sqlite3.oo1.OpfsSAHPool.default instanceof Function) - .assert(sqlite3.oo1.OpfsSAHPool.default === - sqlite3.oo1.OpfsSAHPool[sahPoolConfig.name]) .assert(sqlite3.capi.sqlite3_js_vfs_list().indexOf(sahPoolConfig.name) >= 0); T.assert(0 === u1.getFileCount()); - const DbCtor = sqlite3.oo1.OpfsSAHPool.default; const dbName = '/foo.db'; - let db = new DbCtor(dbName); - T.assert(1 === u1.getFileCount()); + let db = new u1.OpfsSAHPoolDb(dbName); + T.assert(db instanceof sqlite3.oo1.DB) + .assert(1 === u1.getFileCount()); db.exec([ 'create table t(a);', 'insert into t(a) values(1),(2),(3)' @@ -3072,14 +3069,19 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(3 === db.selectValue('select count(*) from t')); db.close(); T.assert(1 === u1.getFileCount()); - db = new DbCtor(dbName); + db = new u2.OpfsSAHPoolDb(dbName); T.assert(1 === u1.getFileCount()); db.close(); T.assert(1 === u1.getFileCount()) .assert(true === u1.unlink(dbName)) .assert(false === u1.unlink(dbName)) .assert(0 === u1.getFileCount()); - + if(0){ + /* Enable this block to inspect vfs's contents via the dev + console or OPFS Explorer browser extension. The + following bits will remove them. */ + return; + } T.assert(true === await u2.removeVfs()) .assert(false === await u1.removeVfs()) .assert(!sqlite3.capi.sqlite3_vfs_find(sahPoolConfig.name)); diff --git a/manifest b/manifest index 9bf3bd22cd..9e1fc1f83f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sinternal\srefactoring\sand\sdocs\sfor\sopfs-sahpool. -D 2023-07-19T17:47:02.768 +C Filter\sthe\sOPFS\sVFSes\sout\sof\sthe\ssqlite3-node.mjs\sbuild.\sAdd\sanother\slevel\sof\ssubdirectory\sto\sthe\ssahpool\sto\slater\senable\stransparent\ssupport\sof\sclient-provided\sfiles\sunder\sthe\sVFS's\sroot\sdir.\sRework\sthe\sawkward\ssahpool-via-oo1\smapping. +D 2023-07-20T09:06:42.459 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -482,13 +482,13 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile b425091409491f0f9dca77f7a41143530f8b7d37abfb3ba59f1d50f4cc85d02f +F ext/wasm/GNUmakefile 437beb3e200cb8b2977dbda43caecd30edb87a7cf4fa2d86cb6179a1858fe466 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md 0895244c0539ae68cf8c70d59c2de512532fd47cfba313268e2b672e6359112e F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 -F ext/wasm/api/README.md f6cec6b0ce122cdff9440b30a3132dea3665b5b7baace910b43cbccdaaa376b9 +F ext/wasm/api/README.md 5eb44fa02e9c693a1884a3692428647894b0380b24bca120866b7a24c8786134 F ext/wasm/api/extern-post-js.c-pp.js 80f288131f9f4486a66e79dbf42d4402dc23e3cb4ef605377ae69f0545a6b8e6 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 @@ -502,8 +502,8 @@ F ext/wasm/api/sqlite3-api-worker1.js 9f32af64df1a031071912eea7a201557fe39b17386 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 F ext/wasm/api/sqlite3-v-helper.js 7daa0eab0a513a25b05e9abae7b5beaaa39209b3ed12f86aeae9ef8d2719ed25 -F ext/wasm/api/sqlite3-vfs-opfs-sahpool.js 05b5646b91faa947833d43a840e8b94abb441afa953ee5a11cc7f07f4e01361a -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 4946af0d6fbd395aa39966562ca85900664605a5f0cc10fff50146dee527812c +F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js d9abf3cde87aea55ea901e80f70e55b36055e8e5120ed47321af35afb9facdaa w ext/wasm/api/sqlite3-vfs-opfs-sahpool.js +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 7b6aa73e8af0379f96d17eb874bc02ed13e901c6924aa3804a075f7bc58c3146 F ext/wasm/api/sqlite3-wasm.c 8867f1d41c112fb4a2cfe22ff224eccaf309fcdea266cee0ec554f85db72ef0f F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bc06df0d599e625bde6a10a394e326dc68da9ff07fa5404354580f81566e591f F ext/wasm/api/sqlite3-worker1.c-pp.js da509469755035e919c015deea41b4514b5e84c12a1332e6cc8d42cb2cc1fb75 @@ -549,7 +549,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js f09266873e1a34d9bdb6d3981ec8c9e382f31f215c9fd2f9016d2394b8ae9b7b F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js b99aa30d9b54c5c60f67381b249d290a542c529898852c32c5645f5a33be9498 +F ext/wasm/tester1.c-pp.js f835c9f703b562142f23a3607fa4a34cb6aece5fb5d674ea5bd7d37b0e47e104 F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2044,8 +2044,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 500109bd0a4c134b91c37f397ff1ee828e09c17f7ecd153f975ede748caee7bb -R 44dc85544ec440f7c21f7b899d57ed02 +P 64ccf6177a019eab46fb3345ad1e8ba80eaf2c9da55767031f9f04ccd16afb4d +R 9b88832176f0fa72b79f47fe01f46afd U stephan -Z e1c9bd04ae7a0c44d52816708800bbbb +Z 925e0249217422a96f201bda7e782884 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d4e846dedc..450c8fa540 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -64ccf6177a019eab46fb3345ad1e8ba80eaf2c9da55767031f9f04ccd16afb4d \ No newline at end of file +080a4d0aba30d8f3802b49be4a113205f069b3bdea8cebf525d654055642ff62 \ No newline at end of file