hypercore-storage 1.12.0 → 1.12.1

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/lib/tx.js CHANGED
@@ -35,6 +35,10 @@ class CoreTX {
35
35
  this.changes.push([core.head(this.core.dataPointer), encode(CORE_HEAD, head), null])
36
36
  }
37
37
 
38
+ deleteHead () {
39
+ this.changes.push([core.head(this.core.dataPointer), null, null])
40
+ }
41
+
38
42
  setDependency (dep) {
39
43
  this.changes.push([core.dependency(this.core.dataPointer), encode(CORE_DEPENDENCY, dep), null])
40
44
  }
@@ -373,7 +373,27 @@ async function core (core, { version, dryRun = true, gc = true }) {
373
373
  }
374
374
 
375
375
  const oplog = await readOplog(files.oplog)
376
- if (!oplog) throw new Error('No oplog available for ' + files.oplog + ', length = ' + (head ? head.length : 0) + ', writable = ' + (!!auth.keyPair))
376
+ if (!oplog) {
377
+ const writable = !!auth.keyPair
378
+
379
+ if (writable) {
380
+ throw new Error('No oplog available writable core for ' + files.oplog + ', length = ' + (head ? head.length : 0))
381
+ }
382
+
383
+ // if not writable, just nuke it to recover, some bad state happened here, prop corruption from earlier versions
384
+ const w = core.write()
385
+
386
+ w.deleteBlockRange(0, -1)
387
+ w.deleteTreeNodeRange(0, -1)
388
+ w.deleteBitfieldPageRange(0, -1)
389
+ w.deleteHead()
390
+
391
+ await w.flush()
392
+
393
+ await commitCoreMigration(auth, core, version)
394
+ if (gc) await runGC()
395
+ return // no data
396
+ }
377
397
 
378
398
  const treeData = new TreeSlicer()
379
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",