Comparing version
41
index.js
@@ -377,2 +377,32 @@ const b4a = require('b4a') | ||
async _getMigrationPointer (key, length) { | ||
const encryption = this.encryptionKey | ||
? { key: AutoStore.getBlockKey(this.bootstrap, this.encryptionKey, '_system'), block: true } | ||
: null | ||
const core = this.store.get({ key, active: false, encryption }) | ||
await core.ready() | ||
for (let i = length - 1; i >= 0; i--) { | ||
if (!(await core.has(i))) continue | ||
const sys = new SystemView(core, { checkout: i + 1 }) | ||
await sys.ready() | ||
let good = true | ||
for (const v of sys.views) { | ||
const vc = this.store.get({ key: v.key, active: false }) | ||
await vc.ready() | ||
if (vc.length < v.length) good = false | ||
await vc.close() | ||
} | ||
await sys.close() | ||
if (!good) continue | ||
return i + 1 | ||
} | ||
} | ||
// migrating from 6 -> latest | ||
@@ -439,5 +469,14 @@ async _migrate6 (key, length) { | ||
const pointer = await this.local.getUserData('autobase/boot') | ||
return pointer | ||
const boot = pointer | ||
? c.decode(messages.BootRecord, pointer) | ||
: { key: null, indexedLength: 0, indexersUpdated: false, fastForwarding: false, recoveries: RECOVERIES, heads: null } | ||
if (boot.heads) { | ||
const len = await this._getMigrationPointer(boot.key, boot.indexedLength) | ||
if (len !== boot.indexedLength) this._warn(new Error('Invalid pointer in migration, correcting (' + len + ' vs ' + boot.indexedLength + ')')) | ||
boot.indexedLength = len | ||
} | ||
return boot | ||
} | ||
@@ -444,0 +483,0 @@ |
{ | ||
"name": "autobase", | ||
"version": "7.0.41", | ||
"version": "7.0.42", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
188629
0.58%5104
0.55%