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

Commit

Permalink
fix: handle no mfs root found (#138)
Browse files Browse the repository at this point in the history
Only migrate the mfs root key if it exists

Backport from ipfs/js-ipfs-repo#339
  • Loading branch information
achingbrain authored Sep 13, 2021
1 parent d771359 commit f9cb0a2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions migrations/migration-11/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
await backends.root.open()
await backends.datastore.open()

const root = await backends.root.get(MFS_ROOT_KEY)
await backends.datastore.put(MFS_ROOT_KEY, root)
await backends.root.delete(MFS_ROOT_KEY)
if (await backends.root.has(MFS_ROOT_KEY)) {
const root = await backends.root.get(MFS_ROOT_KEY)
await backends.datastore.put(MFS_ROOT_KEY, root)
await backends.root.delete(MFS_ROOT_KEY)
}

await backends.datastore.close()
await backends.root.close()
Expand All @@ -34,9 +36,11 @@ async function storeMfsRootInRoot (backends, onProgress = () => {}) {
await backends.root.open()
await backends.datastore.open()

const root = await backends.datastore.get(MFS_ROOT_KEY)
await backends.root.put(MFS_ROOT_KEY, root)
await backends.datastore.delete(MFS_ROOT_KEY)
if (await backends.datastore.has(MFS_ROOT_KEY)) {
const root = await backends.datastore.get(MFS_ROOT_KEY)
await backends.root.put(MFS_ROOT_KEY, root)
await backends.datastore.delete(MFS_ROOT_KEY)
}

await backends.datastore.close()
await backends.root.close()
Expand Down

0 comments on commit f9cb0a2

Please sign in to comment.