-
Couldn't load subscription status.
- Fork 83
Fill in IDBBatchAtomicVFS blocks on writes past EOF #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,8 @@ class File { | |||||||||||
| /** @type {number} */ flags; | ||||||||||||
|
|
||||||||||||
| /** @type {Metadata} */ metadata; | ||||||||||||
| /** @type {number} */ fileSize = 0; | ||||||||||||
|
|
||||||||||||
| /** @type {boolean} */ needsMetadataSync = false; | ||||||||||||
|
|
||||||||||||
| /** @type {Metadata} */ rollback = null; | ||||||||||||
| /** @type {Set<number>} */ changedPages = new Set(); | ||||||||||||
|
|
||||||||||||
|
|
@@ -259,13 +258,30 @@ export class IDBBatchAtomicVFS extends WebLocksMixin(FacadeVFS) { | |||||||||||
| if (!isOverwrite || | ||||||||||||
| file.flags & VFS.SQLITE_OPEN_MAIN_DB || | ||||||||||||
| file.flags & VFS.SQLITE_OPEN_TEMP_DB) { | ||||||||||||
| const snapshotFileSize = file.metadata.fileSize; | ||||||||||||
| const block = { | ||||||||||||
| path: file.path, | ||||||||||||
| offset: -iOffset, | ||||||||||||
| version: version, | ||||||||||||
| data: pData.slice() | ||||||||||||
| data | ||||||||||||
| }; | ||||||||||||
| this.#idb.q(({ blocks }) => { | ||||||||||||
| if (file.flags & (VFS.SQLITE_OPEN_MAIN_DB | VFS.SQLITE_OPEN_TEMP_DB)) { | ||||||||||||
| // If this write is past the end of the file, insert blocks | ||||||||||||
| // for the skipped space. Note that we can't test against | ||||||||||||
| // file.metadata.fileSize because that will have changed | ||||||||||||
| // by the time this lambda is executed. | ||||||||||||
| for (let skipOffset = snapshotFileSize; | ||||||||||||
| skipOffset < iOffset; skipOffset += data.byteLength) { | ||||||||||||
| blocks.put({ | ||||||||||||
| path: file.path, | ||||||||||||
| offset: -skipOffset, | ||||||||||||
| version: version, | ||||||||||||
| data: new Uint8Array(data.byteLength) | ||||||||||||
| }); | ||||||||||||
| file.changedPages.add(skipOffset); | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+274
to
+283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||
| } | ||||||||||||
| blocks.put(block); | ||||||||||||
| file.changedPages.add(iOffset); | ||||||||||||
|
Comment on lines
285
to
286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||
| }, 'rw', file.txOptions); | ||||||||||||
|
|
@@ -284,7 +300,6 @@ export class IDBBatchAtomicVFS extends WebLocksMixin(FacadeVFS) { | |||||||||||
| // Write back. | ||||||||||||
| blocks.put(block); | ||||||||||||
| }, 'rw', file.txOptions); | ||||||||||||
|
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (file.metadata.fileSize < iOffset + pData.length) { | ||||||||||||
|
|
@@ -454,6 +469,7 @@ export class IDBBatchAtomicVFS extends WebLocksMixin(FacadeVFS) { | |||||||||||
| if (file.flags & VFS.SQLITE_OPEN_MAIN_DB) { | ||||||||||||
| // Don't allow changing the page size. | ||||||||||||
| if (value && file.metadata.fileSize) { | ||||||||||||
| console.error('IDBBatchAtomicVFS page size cannot be changed.'); | ||||||||||||
| return VFS.SQLITE_ERROR; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
data.slice()here to avoid potential modification of the originalpDatabuffer. While the current implementation works, explicitly creating a copy ensures that any subsequent changes topDatado not affect the data stored in the block.