Skip to content

Commit 32d9fc0

Browse files
Fix xUnlock() call without prior call to xLock() (rhashimoto#245)
* Fix jUnlock() call without prior jLock(). * Call super method from OPFSAdaptiveVFS.jFileControl(). --------- Co-authored-by: Roy Hashimoto <roy@shoestringresearch.com>
1 parent d1f6248 commit 32d9fc0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/WebLocksMixin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ export const WebLocksMixin = superclass => class extends superclass {
8282
*/
8383
async jUnlock(fileId, lockType) {
8484
try {
85+
// SQLite can call xUnlock() without ever calling xLock() so
86+
// the state may not exist.
8587
const lockState = this.#mapIdToState.get(fileId);
86-
if (lockType >= lockState.type) return VFS.SQLITE_OK;
88+
if (!(lockType < lockState?.type)) return VFS.SQLITE_OK;
8789

8890
switch (this.#options.lockPolicy) {
8991
case 'exclusive':
@@ -122,17 +124,17 @@ export const WebLocksMixin = superclass => class extends superclass {
122124
}
123125

124126
/**
125-
* @param {number} pFile
127+
* @param {number} fileId
126128
* @param {number} op
127129
* @param {DataView} pArg
128130
* @returns {number|Promise<number>}
129131
*/
130-
jFileControl(pFile, op, pArg) {
131-
const lockState = this.#mapIdToState.get(pFile) ??
132+
jFileControl(fileId, op, pArg) {
133+
const lockState = this.#mapIdToState.get(fileId) ??
132134
(() => {
133135
// Call jLock() to create the lock state.
134-
this.jLock(pFile, VFS.SQLITE_LOCK_NONE);
135-
return this.#mapIdToState.get(pFile);
136+
this.jLock(fileId, VFS.SQLITE_LOCK_NONE);
137+
return this.#mapIdToState.get(fileId);
136138
})();
137139
if (op === WebLocksMixin.WRITE_HINT_OP_CODE &&
138140
this.#options.lockPolicy === 'shared+hint'){

src/examples/OPFSAdaptiveVFS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class OPFSAdaptiveVFS extends WebLocksMixin(FacadeVFS) {
413413
this.lastError = e;
414414
return VFS.SQLITE_IOERR;
415415
}
416-
return VFS.SQLITE_NOTFOUND;
416+
return super.jFileControl(fileId, op, pArg);
417417
}
418418

419419
jGetLastError(zBuf) {

0 commit comments

Comments
 (0)