aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2024-10-17 12:14:34 +0000
committerstephan <stephan@noemail.net>2024-10-17 12:14:34 +0000
commitcab9574668c9d5d8d6da8763860cd95f8d2a787e (patch)
tree6b15c177e55c4931d22c5bb0d2a6efb09efb2e31 /ext/wasm
parent6031de92c6e06e014323cab81e4c0ac77123fa27 (diff)
downloadsqlite-cab9574668c9d5d8d6da8763860cd95f8d2a787e.tar.gz
sqlite-cab9574668c9d5d8d6da8763860cd95f8d2a787e.zip
Ensure that the OPFS VFS's xOpen() writes back the read-only flag to the output flags. Resolves the problem reported in [forum:cf37d5ff1182c31081 | forum post cf37d5ff1182c31081].
FossilOrigin-Name: 0a32624015f16fd881a4ecbb56b7833391028d327a95f4c899eee864ed7fe00d
Diffstat (limited to 'ext/wasm')
-rw-r--r--ext/wasm/api/sqlite3-opfs-async-proxy.js3
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs.c-pp.js2
-rw-r--r--ext/wasm/tester1.c-pp.js64
3 files changed, 39 insertions, 30 deletions
diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js
index ca5583971..0028c1025 100644
--- a/ext/wasm/api/sqlite3-opfs-async-proxy.js
+++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js
@@ -506,8 +506,7 @@ const installAsyncProxy = function(){
dirHandle: hDir,
fileHandle: hFile,
sabView: state.sabFileBufView,
- readOnly: create
- ? false : (state.sq3Codes.SQLITE_OPEN_READONLY & flags),
+ readOnly: !create && !!(state.sq3Codes.SQLITE_OPEN_READONLY & flags),
deleteOnClose: !!(state.sq3Codes.SQLITE_OPEN_DELETEONCLOSE & flags)
});
fh.releaseImplicitLocks =
diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
index 2d11b3583..27f1bfae7 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
@@ -922,6 +922,8 @@ const installOpfsVfs = function callee(options){
fh.filename = zName;
fh.sab = new SharedArrayBuffer(state.fileBufferSize);
fh.flags = flags;
+ fh.readOnly = !(sqlite3.SQLITE_OPEN_CREATE & flags)
+ && !!(flags & capi.SQLITE_OPEN_READONLY);
const rc = opRun('xOpen', pFile, zName, flags, opfsFlags);
if(!rc){
/* Recall that sqlite3_vfs::xClose() will be called, even on
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index 74596b9ba..4347c8fd7 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -3360,40 +3360,48 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
predicate: ()=>hasOpfs() || "Requires OPFS to reproduce",
//predicate: ()=>false,
test: async function(sqlite3){
- /* https://sqlite.org/forum/forumpost/cf37d5ff11 */
+ /* https://sqlite.org/forum/forumpost/cf37d5ff1182c31081
+
+ The "opfs" VFS (but not SAHPool) was formerly misbehaving
+ after a write attempt was made on a db opened with
+ mode=ro. This test ensures that that behavior is fixed and
+ compares that behavior with other VFSes. */
+ const tryOne = function(vfsName,descr){
+ const uri = 'file:///foo.db';
+ let db = new sqlite3.oo1.DB(uri + (vfsName ? '?vfs='+vfsName : ''));
+ db.exec([
+ "drop table if exists t;",
+ "create table t(a);",
+ "insert into t(a) values('abc'),('def'),('ghi');"
+ ]);
+ db.close();
+ db = new sqlite3.oo1.DB(uri+'?mode=ro'+
+ (vfsName ? '&vfs='+vfsName : ''));
+ let err;
+ try {
+ db.exec('insert into t(a) values(1)');
+ }catch(e){
+ err = e;
+ }
+ T.assert(err && (err.message.indexOf('SQLITE_READONLY')===0));
+ try{
+ db.exec('select a from t');
+ }finally{
+ db.close();
+ }
+ };
const poolConfig = JSON.parse(JSON.stringify(sahPoolConfig));
poolConfig.name = 'opfs-sahpool-cf37d5ff11';
- const vfsName = 0 ? poolConfig.name : (1 ? undefined : 'opfs');
let poolUtil;
- const uri = 'file:///foo.db';
- //log('poolConfig =',poolConfig);
- if( poolConfig.name === vfsName ){
- await sqlite3.installOpfsSAHPoolVfs(poolConfig).then(p=>poolUtil=p);
- T.assert(!!sqlite3.capi.sqlite3_vfs_find(poolConfig.name), "Expecting to find just-registered VFS");
- }
- let db = new sqlite3.oo1.DB(uri + (vfsName ? '?vfs='+vfsName : ''));
- db.exec([
- "drop table if exists t;",
- "create table t(a);",
- "insert into t(a) values('abc'),('def'),('ghi');"
- ]);
- db.close();
- db = new sqlite3.oo1.DB(uri+'?mode=ro'+(vfsName ? '&vfs='+vfsName : ''));
- let err;
- try {
- db.exec('insert into t(a) values(1)');
- }catch(e){
- err = e;
- }
- //log("err =",err);
- T.assert(err && (err.message.indexOf('SQLITE_IOERR_WRITE')===0/*opfs*/
- || err.message.indexOf('readonly')>0)/*Emscripten FS*/);
+ await sqlite3.installOpfsSAHPoolVfs(poolConfig).then(p=>poolUtil=p);
+ T.assert(!!sqlite3.capi.sqlite3_vfs_find(poolConfig.name), "Expecting to find just-registered VFS");
try{
- db.exec('select a from t');
+ tryOne(false, "Emscripten filesystem");
+ tryOne(poolConfig.name);
+ tryOne('opfs');
}finally{
- db.close();
+ await poolUtil.removeVfs();
}
- if( poolUtil ) await poolUtil.removeVfs();
}
})
;/*end of Bug Reports group*/;