1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

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
This commit is contained in:
stephan
2023-08-04 16:01:55 +00:00
parent b87278f414
commit 195611d8e6
3 changed files with 26 additions and 12 deletions

View File

@ -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