From bf030d53b14bc38fbdc745636ef8dffdd57a1fa0 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 11 Mar 2024 09:32:38 +0000 Subject: 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: e83f9788636f7f9bcca7d2a09620c13ab4eb83436d5b2946a827e48addf0267d --- ext/wasm/api/sqlite3-opfs-async-proxy.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ext/wasm/api/sqlite3-opfs-async-proxy.js') diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index cafd296c6..58b8bcb23 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -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),{ -- cgit v1.2.3