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

Commit a42e671

Browse files
authored
fix: null-guard progress and enable migration 9 (#34)
Also use the `ipfs:` namespace for logs
1 parent 492a487 commit a42e671

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

migrations/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
// Do not modify this file manually as it will be overridden when running 'add' CLI command.
4-
// Modify migration-templates.js file
5-
63
const emptyMigration = {
74
description: 'Empty migration.',
85
migrate: () => {},
@@ -18,5 +15,6 @@ module.exports = [
1815
Object.assign({version: 5}, emptyMigration),
1916
Object.assign({version: 6}, emptyMigration),
2017
Object.assign({version: 7}, emptyMigration),
21-
require('./migration-8')
18+
require('./migration-8'),
19+
require('./migration-9')
2220
]

migrations/migration-8/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const CID = require('cids')
44
const Key = require('interface-datastore').Key
55
const mb = require('multibase')
6-
const log = require('debug')('ipfs-repo-migrations:migration-8')
6+
const log = require('debug')('ipfs:repo:migrator:migration-8')
77
const uint8ArrayToString = require('uint8arrays/to-string')
88
const { createStore } = require('../../src/utils')
99
const length = require('it-length')

migrations/migration-9/index.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
1515
const cid = new CID(mh)
1616
const pinRootBuf = await blockstore.get(cidToKey(cid))
1717
const pinRoot = dagpb.util.deserialize(pinRootBuf)
18-
19-
const pinCount = (await length(pinset.loadSet(blockstore, pinRoot, PinTypes.recursive))) + (await length(pinset.loadSet(blockstore, pinRoot, PinTypes.direct)))
2018
let counter = 0
19+
let pinCount
20+
21+
if (onProgress) {
22+
pinCount = (await length(pinset.loadSet(blockstore, pinRoot, PinTypes.recursive))) + (await length(pinset.loadSet(blockstore, pinRoot, PinTypes.direct)))
23+
}
2124

2225
for await (const cid of pinset.loadSet(blockstore, pinRoot, PinTypes.recursive)) {
2326
counter++
@@ -35,7 +38,9 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
3538

3639
await pinstore.put(cidToKey(cid), cbor.encode(pin))
3740

38-
onProgress((counter / pinCount) * 100, `Migrated recursive pin ${cid}`)
41+
if (onProgress) {
42+
onProgress((counter / pinCount) * 100, `Migrated recursive pin ${cid}`)
43+
}
3944
}
4045

4146
for await (const cid of pinset.loadSet(blockstore, pinRoot, PinTypes.direct)) {
@@ -64,15 +69,13 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
6469
async function pinsToDAG (blockstore, datastore, pinstore, onProgress) {
6570
let recursivePins = []
6671
let directPins = []
67-
72+
let counter = 0
6873
let pinCount
6974

7075
if (onProgress) {
7176
pinCount = await length(pinstore.query({ keysOnly: true }))
7277
}
7378

74-
let counter = 0
75-
7679
for await (const { key, value } of pinstore.query({})) {
7780
counter++
7881
const pin = cbor.decode(value)

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const repoVersion = require('./repo/version')
55
const repoLock = require('./repo/lock')
66
const errors = require('./errors')
77

8-
const log = require('debug')('repo-migrations:migrator')
8+
const log = require('debug')('ipfs:repo:migrator')
99

1010
exports.getCurrentRepoVersion = repoVersion.getVersion
1111
exports.errors = errors

src/repo/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const log = require('debug')('repo-migrations:repo:init')
3+
const log = require('debug')('ipfs:repo:migrator:repo:init')
44
const { CONFIG_KEY, VERSION_KEY, createStore } = require('../utils')
55
const { MissingRepoOptionsError } = require('../errors')
66

src/repo/lock-memory.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const debug = require('debug')
4-
5-
const log = debug('repo-migrations:repo_mem_lock')
6-
4+
const log = debug('ipfs:repo:migrator:repo_mem_lock')
75
const lockFile = 'repo.lock'
8-
96
const LOCKS = {}
107

118
/**

src/repo/lock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const debug = require('debug')
44
const { lock } = require('proper-lockfile')
55

6-
const log = debug('repo-migrations:repo_fs_lock')
6+
const log = debug('ipfs:repo:migrator:repo_fs_lock')
77
const lockFile = 'repo.lock'
88

99
/**

0 commit comments

Comments
 (0)