Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit f9cb0a2

Browse files
authored
fix: handle no mfs root found (#138)
Only migrate the mfs root key if it exists Backport from ipfs/js-ipfs-repo#339
1 parent d771359 commit f9cb0a2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

migrations/migration-11/index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
1414
await backends.root.open()
1515
await backends.datastore.open()
1616

17-
const root = await backends.root.get(MFS_ROOT_KEY)
18-
await backends.datastore.put(MFS_ROOT_KEY, root)
19-
await backends.root.delete(MFS_ROOT_KEY)
17+
if (await backends.root.has(MFS_ROOT_KEY)) {
18+
const root = await backends.root.get(MFS_ROOT_KEY)
19+
await backends.datastore.put(MFS_ROOT_KEY, root)
20+
await backends.root.delete(MFS_ROOT_KEY)
21+
}
2022

2123
await backends.datastore.close()
2224
await backends.root.close()
@@ -34,9 +36,11 @@ async function storeMfsRootInRoot (backends, onProgress = () => {}) {
3436
await backends.root.open()
3537
await backends.datastore.open()
3638

37-
const root = await backends.datastore.get(MFS_ROOT_KEY)
38-
await backends.root.put(MFS_ROOT_KEY, root)
39-
await backends.datastore.delete(MFS_ROOT_KEY)
39+
if (await backends.datastore.has(MFS_ROOT_KEY)) {
40+
const root = await backends.datastore.get(MFS_ROOT_KEY)
41+
await backends.root.put(MFS_ROOT_KEY, root)
42+
await backends.datastore.delete(MFS_ROOT_KEY)
43+
}
4044

4145
await backends.datastore.close()
4246
await backends.root.close()

0 commit comments

Comments
 (0)