hypercore 11.0.4 → 11.0.5
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 +2 -2
- package/lib/session-state.js +6 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -341,14 +341,14 @@ class Hypercore extends EventEmitter {
|
|
|
341
341
|
|
|
342
342
|
const parent = opts.parent || this.core
|
|
343
343
|
const checkout = opts.checkout === undefined ? -1 : opts.checkout
|
|
344
|
+
const state = this.state
|
|
344
345
|
|
|
345
346
|
if (opts.atom) {
|
|
346
347
|
this.state = await parent.state.createSession(null, checkout, false, opts.atom)
|
|
348
|
+
if (state) state.unref()
|
|
347
349
|
} else if (opts.name) {
|
|
348
350
|
// todo: need to make named sessions safe before ready
|
|
349
351
|
// atm we always copy the state in passCapabilities
|
|
350
|
-
const state = this.state
|
|
351
|
-
|
|
352
352
|
this.state = await parent.state.createSession(opts.name, checkout, !!opts.overwrite, null)
|
|
353
353
|
if (state) state.unref() // ref'ed above in setup session
|
|
354
354
|
|
package/lib/session-state.js
CHANGED
|
@@ -241,6 +241,8 @@ module.exports = class SessionState {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
this._moveToCore(src.core)
|
|
244
|
+
|
|
245
|
+
await this.storage.close()
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
const truncated = (bitfield && bitfield.truncated !== -1)
|
|
@@ -798,8 +800,9 @@ module.exports = class SessionState {
|
|
|
798
800
|
const treeLength = this.length
|
|
799
801
|
|
|
800
802
|
if (!this.isSnapshot()) {
|
|
801
|
-
const
|
|
803
|
+
const oldStorage = this.storage
|
|
802
804
|
|
|
805
|
+
const truncation = length < this.length ? await truncateAndFlush(this, length) : null
|
|
803
806
|
const treeInfo = truncation ? truncation.tree : await state._getTreeHeadAt(this.length)
|
|
804
807
|
|
|
805
808
|
treeInfo.fork = truncation ? this.fork + 1 : this.fork
|
|
@@ -827,6 +830,8 @@ module.exports = class SessionState {
|
|
|
827
830
|
if (dependency) this.storage.updateDependencyLength(this.dependencyLength)
|
|
828
831
|
this.ontruncate(tree, tree.length, treeLength, flushed)
|
|
829
832
|
}
|
|
833
|
+
|
|
834
|
+
await oldStorage.close()
|
|
830
835
|
}
|
|
831
836
|
|
|
832
837
|
if (!this.storage.atom) {
|