Add delete-before-open=1 URI flag to the 'opfs' VFS to tell it to xDelete the db file before opening it, primarily to enable users to work around a corrupt db without having to reach into OPFS-specific APIs to remove the db file.
FossilOrigin-Name: e87cf0d7700d33a439c91725460fbfe3a1765b48f71b4d73c38cadf6c166e0bd
This commit is contained in:
commit
88abf9ad44
@ -562,6 +562,17 @@ const installAsyncProxy = function(self){
|
||||
wTimeEnd();
|
||||
return;
|
||||
}
|
||||
if( state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN & opfsFlags ){
|
||||
//log("async proxy opfsFlags =",opfsFlags);
|
||||
try{
|
||||
await hDir.removeEntry(filenamePart);
|
||||
//log("Unlinked",filename,hDir,filenamePart);
|
||||
}
|
||||
catch(e){
|
||||
/* ignoring */
|
||||
//warn("Ignoring failed Unlink of",filename,":",e);
|
||||
}
|
||||
}
|
||||
const hFile = await hDir.getFileHandle(filenamePart, {create});
|
||||
wTimeEnd();
|
||||
const fh = Object.assign(Object.create(null),{
|
||||
|
@ -423,10 +423,18 @@ const installOpfsVfs = function callee(options){
|
||||
});
|
||||
state.opfsFlags = Object.assign(Object.create(null),{
|
||||
/**
|
||||
Flag for use with xOpen(). "opfs-unlock-asap=1" enables
|
||||
this. See defaultUnlockAsap, below.
|
||||
Flag for use with xOpen(). URI flag "opfs-unlock-asap=1"
|
||||
enables this. See defaultUnlockAsap, below.
|
||||
*/
|
||||
OPFS_UNLOCK_ASAP: 0x01,
|
||||
/**
|
||||
Flag for use with xOpen(). URI flag "delete-before-open=1"
|
||||
tells the VFS to delete the db file before attempting to open
|
||||
it. This can be used, e.g., to replace a db which has been
|
||||
corrupted (without forcing us to expose a delete/unlink()
|
||||
function in the public API).
|
||||
*/
|
||||
OPFS_UNLINK_BEFORE_OPEN: 0x02,
|
||||
/**
|
||||
If true, any async routine which implicitly acquires a sync
|
||||
access handle (i.e. an OPFS lock) will release that locks at
|
||||
@ -875,13 +883,17 @@ const installOpfsVfs = function callee(options){
|
||||
let opfsFlags = 0;
|
||||
if(0===zName){
|
||||
zName = randomFilename();
|
||||
}else if('number'===typeof zName){
|
||||
}else if(wasm.isPtr(zName)){
|
||||
if(capi.sqlite3_uri_boolean(zName, "opfs-unlock-asap", 0)){
|
||||
/* -----------------------^^^^^ MUST pass the untranslated
|
||||
C-string here. */
|
||||
opfsFlags |= state.opfsFlags.OPFS_UNLOCK_ASAP;
|
||||
}
|
||||
if(capi.sqlite3_uri_boolean(zName, "delete-before-open", 0)){
|
||||
opfsFlags |= state.opfsFlags.OPFS_UNLINK_BEFORE_OPEN;
|
||||
}
|
||||
zName = wasm.cstrToJs(zName);
|
||||
//warn("xOpen zName =",zName, "opfsFlags =",opfsFlags);
|
||||
}
|
||||
const fh = Object.create(null);
|
||||
fh.fid = pFile;
|
||||
|
@ -2888,18 +2888,17 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
||||
.t({
|
||||
name: 'OPFS db sanity checks',
|
||||
test: async function(sqlite3){
|
||||
T.assert(capi.sqlite3_vfs_find('opfs'));
|
||||
const opfs = sqlite3.opfs;
|
||||
const filename = this.opfsDbFile = '/dir/sqlite3-tester1.db';
|
||||
const pVfs = this.opfsVfs = capi.sqlite3_vfs_find('opfs');
|
||||
T.assert(pVfs);
|
||||
const unlink = this.opfsUnlink =
|
||||
(fn=filename)=>{sqlite3.util.sqlite3__wasm_vfs_unlink(pVfs,fn)};
|
||||
unlink();
|
||||
let db = new sqlite3.oo1.OpfsDb(filename);
|
||||
const fileUri = 'file://'+filename+'?delete-before-open=1';
|
||||
const initSql = [
|
||||
'create table p(a);',
|
||||
'insert into p(a) values(1),(2),(3)'
|
||||
];
|
||||
let db = new sqlite3.oo1.OpfsDb(fileUri);
|
||||
try {
|
||||
db.exec([
|
||||
'create table p(a);',
|
||||
'insert into p(a) values(1),(2),(3)'
|
||||
]);
|
||||
db.exec(initSql);
|
||||
T.assert(3 === db.selectValue('select count(*) from p'));
|
||||
db.close();
|
||||
db = new sqlite3.oo1.OpfsDb(filename);
|
||||
@ -2911,7 +2910,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
||||
&& 0===this.opfsDbExport.byteLength % 512);
|
||||
}finally{
|
||||
db.close();
|
||||
unlink();
|
||||
}
|
||||
T.assert(await opfs.entryExists(filename));
|
||||
try {
|
||||
db = new sqlite3.oo1.OpfsDb(fileUri);
|
||||
db.exec(initSql) /* will throw if delete-before-open did not work */;
|
||||
T.assert(3 === db.selectValue('select count(*) from p'));
|
||||
}finally{
|
||||
if(db) db.close();
|
||||
}
|
||||
}
|
||||
}/*OPFS db sanity checks*/)
|
||||
@ -2919,15 +2925,17 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
||||
name: 'OPFS import',
|
||||
test: async function(sqlite3){
|
||||
let db;
|
||||
const filename = this.opfsDbFile;
|
||||
try {
|
||||
const exp = this.opfsDbExport;
|
||||
const filename = this.opfsDbFile;
|
||||
delete this.opfsDbExport;
|
||||
this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, exp);
|
||||
db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
|
||||
T.assert(6 === db.selectValue('select count(*) from p')).
|
||||
assert( this.opfsImportSize == exp.byteLength );
|
||||
db.close();
|
||||
const unlink = this.opfsUnlink =
|
||||
(fn=filename)=>sqlite3.util.sqlite3__wasm_vfs_unlink("opfs",fn);
|
||||
this.opfsUnlink(filename);
|
||||
T.assert(!(await sqlite3.opfs.entryExists(filename)));
|
||||
// Try again with a function as an input source:
|
||||
@ -2954,11 +2962,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
||||
name: '(Internal-use) OPFS utility APIs',
|
||||
test: async function(sqlite3){
|
||||
const filename = this.opfsDbFile;
|
||||
const pVfs = this.opfsVfs;
|
||||
const unlink = this.opfsUnlink;
|
||||
T.assert(filename && pVfs && !!unlink);
|
||||
T.assert(filename && !!unlink);
|
||||
delete this.opfsDbFile;
|
||||
delete this.opfsVfs;
|
||||
delete this.opfsUnlink;
|
||||
/**************************************************************
|
||||
ATTENTION CLIENT-SIDE USERS: sqlite3.opfs is NOT intended
|
||||
|
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\sthe\s.expert\scommand\sin\sthe\sshell\sso\sthat\sit\sdoes\snot\sleak\smemory\sif\snot\nfollowed\sby\sSQL\sand\sso\sthat\sit\sworks\swith\sreverse_unordered_selects.
|
||||
D 2024-03-09T18:41:40.779
|
||||
C Add\sdelete-before-open=1\sURI\sflag\sto\sthe\s'opfs'\sVFS\sto\stell\sit\sto\sxDelete\sthe\sdb\sfile\sbefore\sopening\sit,\sprimarily\sto\senable\susers\sto\swork\saround\sa\scorrupt\sdb\swithout\shaving\sto\sreach\sinto\sOPFS-specific\sAPIs\sto\sremove\sthe\sdb\sfile.
|
||||
D 2024-03-11T09:34:38.171
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -610,10 +610,10 @@ F ext/wasm/api/sqlite3-api-oo1.js 7f3bcf0549ac44cde4b9da0b642d771916738d3f6781fb
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 93a72b07b2a5d964d2edc76a90b439ece49298bd7ba60a1c6ae5d4878213701e
|
||||
F ext/wasm/api/sqlite3-api-worker1.js 8d9c0562831f62218170a3373468d8a0b7a6503b5985e309b69bf71187b525cf
|
||||
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-opfs-async-proxy.js b4c7ce9d7f7957f243d0fbd5b6e28bac80cd3c1b738374cd0c96d89df8f2f316
|
||||
F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
|
||||
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aaedc1bb45489b8365bff7e955a83a8d42a
|
||||
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa
|
||||
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fb12aa55667109cfd76b5f645c4a4aec1a8ed9af59d62e05604b39e6390f54aa
|
||||
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309
|
||||
F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359
|
||||
F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a
|
||||
@ -662,7 +662,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
|
||||
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
|
||||
F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c
|
||||
F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2
|
||||
F ext/wasm/tester1.c-pp.js 7c51d19f3644904156a154ddedd7024539ffba1a4e2df5e1efe10333e5b91b8f
|
||||
F ext/wasm/tester1.c-pp.js 18331ec28d7e63c8e262a9872a8da3964d37b7ac22eabe0016af93f3c6f74cc4
|
||||
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
|
||||
@ -2177,8 +2177,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 76629b2bff01df3d42eef2e93d626c291a2f129bd923498941465e5bca74e9f1
|
||||
R d4c5b88cb6e2dcca46b9c5560f050fe6
|
||||
U drh
|
||||
Z b901e762e961c86b4b7445204eab052b
|
||||
P 7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d
|
||||
R 9e249fa0727bf1c60716395bdc490ae1
|
||||
T +closed e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d Closed\sby\sintegrate-merge.
|
||||
U stephan
|
||||
Z e48b52f183c07790d9437c2d350f2700
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
7ead022edaf7a0cd6a8976a1261246084975c9a5be5c893f6c751bb5f963ac0f
|
||||
e87cf0d7700d33a439c91725460fbfe3a1765b48f71b4d73c38cadf6c166e0bd
|
Loading…
Reference in New Issue
Block a user