Skip to content

Commit 84a6c1e

Browse files
committed
Create transaction in IDBMirrorVFS.jTruncate if necessary.
1 parent 3c20261 commit 84a6c1e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/examples/IDBMirrorVFS.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,7 @@ export class IDBMirrorVFS extends FacadeVFS {
333333

334334
if (file.flags & VFS.SQLITE_OPEN_MAIN_DB) {
335335
if (!file.txActive) {
336-
file.txActive = {
337-
path: file.path,
338-
txId: file.viewTx.txId + 1,
339-
blocks: new Map(),
340-
fileSize: file.blockSize * file.blocks.size,
341-
};
336+
this.#createTx(file);
342337
}
343338
file.txActive.blocks.set(iOffset, pData.slice());
344339
file.txActive.fileSize = Math.max(file.txActive.fileSize, iOffset + pData.byteLength);
@@ -375,6 +370,9 @@ export class IDBMirrorVFS extends FacadeVFS {
375370
const file = this.#mapIdToFile.get(fileId);
376371

377372
if (file.flags & VFS.SQLITE_OPEN_MAIN_DB) {
373+
if (!file.txActive) {
374+
this.#createTx(file);
375+
}
378376
file.txActive.fileSize = iSize;
379377
} else {
380378
// All files that are not main databases are stored in a single
@@ -653,7 +651,7 @@ export class IDBMirrorVFS extends FacadeVFS {
653651
}
654652
}
655653

656-
let truncated = tx.fileSize + file.blockSize;
654+
let truncated = tx.fileSize;
657655
while (file.blocks.delete(truncated)) {
658656
truncated += file.blockSize;
659657
}
@@ -709,6 +707,18 @@ export class IDBMirrorVFS extends FacadeVFS {
709707
file.txWriteHint = false;
710708
}
711709

710+
/**
711+
* @param {File} file
712+
*/
713+
#createTx(file) {
714+
file.txActive = {
715+
path: file.path,
716+
txId: file.viewTx.txId + 1,
717+
blocks: new Map(),
718+
fileSize: file.blockSize * file.blocks.size,
719+
};
720+
}
721+
712722
/**
713723
* @param {File} file
714724
*/

0 commit comments

Comments
 (0)