hypercore-storage 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +9 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -252,8 +252,9 @@ class HypercoreStorage {
|
|
|
252
252
|
|
|
253
253
|
const sessions = existingSessions || []
|
|
254
254
|
const session = getBatch(sessions, name, true)
|
|
255
|
+
const fresh = session.dataPointer === -1
|
|
255
256
|
|
|
256
|
-
if (
|
|
257
|
+
if (fresh) {
|
|
257
258
|
session.dataPointer = await this.store._allocData()
|
|
258
259
|
}
|
|
259
260
|
|
|
@@ -273,6 +274,13 @@ class HypercoreStorage {
|
|
|
273
274
|
if (length > 0) coreTx.setHead(head)
|
|
274
275
|
coreTx.setDependency(core.dependencies[core.dependencies.length - 1])
|
|
275
276
|
|
|
277
|
+
if (!fresh) {
|
|
278
|
+
// nuke all existing state...
|
|
279
|
+
coreTx.deleteBlockRange(0, -1)
|
|
280
|
+
coreTx.deleteTreeNodeRange(0, -1)
|
|
281
|
+
coreTx.deleteBitfieldPageRange(0, -1)
|
|
282
|
+
}
|
|
283
|
+
|
|
276
284
|
await tx.flush()
|
|
277
285
|
|
|
278
286
|
return new HypercoreStorage(this.store, this.db.session(), core, this.atom ? this.view : new View(), this.atom)
|