diff options
author | stephan <stephan@noemail.net> | 2023-08-04 16:01:55 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-08-04 16:01:55 +0000 |
commit | 195611d8e6fc0bba559a49e91e6ceb42e4bdd6ba (patch) | |
tree | 25cd646723230a3d0f36be27b8dc8468ce34ccdb /ext/wasm/api | |
parent | b87278f4146ba0a511d921b22ea94479b175db64 (diff) | |
download | sqlite-195611d8e6fc0bba559a49e91e6ceb42e4bdd6ba.tar.gz sqlite-195611d8e6fc0bba559a49e91e6ceb42e4bdd6ba.zip |
In the opfs-sahpool VFS's importDb() and exportFile() methods, throw if the actually-wrote/read amounts differ from the expected-to-write/read amounts, per feedback in [forum:a4122e986f|forum post a4122e986f].
FossilOrigin-Name: a617ebf4e5d1af1b5b15e9782ad111399caaa3ea7b99bb0c8691c8b4283b6d6e
Diffstat (limited to 'ext/wasm/api')
-rw-r--r-- | ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js index 3ba889c39..709d3414c 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js @@ -854,12 +854,18 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return true; } + //! Documented elsewhere in this file. exportFile(name){ const sah = this.#mapFilenameToSAH.get(name) || toss("File not found:",name); const n = sah.getSize() - HEADER_OFFSET_DATA; - const b = new Uint8Array(n>=0 ? n : 0); - if(n>0) sah.read(b, {at: HEADER_OFFSET_DATA}); + const b = new Uint8Array(n>0 ? n : 0); + if(n>0){ + const nRead = sah.read(b, {at: HEADER_OFFSET_DATA}); + if(nRead != n){ + toss("Expected to read "+n+" bytes but read "+nRead+"."); + } + } return b; } @@ -879,8 +885,13 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const sah = this.#mapFilenameToSAH.get(name) || this.nextAvailableSAH() || toss("No available handles to import to."); - sah.write(bytes, {at: HEADER_OFFSET_DATA}); - this.setAssociatedPath(sah, name, capi.SQLITE_OPEN_MAIN_DB); + const nWrote = sah.write(bytes, {at: HEADER_OFFSET_DATA}); + if(nWrote != n){ + this.setAssociatedPath(sah, '', 0); + toss("Expected to write "+n+" bytes but wrote "+nWrote+"."); + }else{ + this.setAssociatedPath(sah, name, capi.SQLITE_OPEN_MAIN_DB); + } } }/*class OpfsSAHPool*/; @@ -1087,6 +1098,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ automatically clean up any non-database files so importing them is pointless. + On a write error, the handle is removed from the pool and made + available for re-use. + - [async] number reduceCapacity(n) Removes up to `n` entries from the pool, with the caveat that it can |