Skip to content

Commit 180a256

Browse files
authored
Merge pull request rhashimoto#130 from rhashimoto/update-metadata-on-xsync
Fix rhashimoto#110. Ensure metadata is written on xSync.
2 parents 51e1283 + bde2469 commit 180a256

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/examples/IDBBatchAtomicVFS.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ export class IDBBatchAtomicVFS extends VFS.Base {
356356
const file = this.#mapIdToFile.get(fileId);
357357
log(`xSync ${file.path} ${flags}`);
358358
try {
359+
if (file.isMetadataChanged) {
360+
// Metadata has changed so write block 0 to IndexedDB.
361+
this.#idb.run('readwrite', async ({blocks}) => {
362+
await blocks.put(file.block0);
363+
});
364+
file.isMetadataChanged = false;
365+
}
359366
await this.#idb.sync();
360367
} catch (e) {
361368
console.error(e);
@@ -502,6 +509,7 @@ export class IDBBatchAtomicVFS extends VFS.Base {
502509
this.#idb.run('readwrite', async ({blocks}) => {
503510
await blocks.put(file.block0);
504511
});
512+
file.isMetadataChanged = false;
505513
} catch (e) {
506514
console.error(e);
507515
return VFS.SQLITE_IOERR;

0 commit comments

Comments
 (0)