Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a967bb0

Browse files
feat(init): add empty unixfs dir to match go-ipfs
1 parent 9058118 commit a967bb0

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/core/components/init.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const peerId = require('peer-id')
44
const waterfall = require('async/waterfall')
5+
const parallel = require('async/parallel')
56

67
const addDefaultAssets = require('./init-assets')
78

@@ -51,11 +52,28 @@ module.exports = function init (self) {
5152
},
5253
(cb) => self._repo.config.set(config, cb),
5354
(cb) => {
54-
if (typeof addDefaultAssets === 'function' && !opts.emptyRepo) {
55-
return addDefaultAssets(self, opts.log, cb)
55+
if (opts.emptyRepo) {
56+
return cb(null, true)
5657
}
5758

58-
cb(null, true)
59+
const tasks = [
60+
// add empty unixfs dir object (go-ipfs assumes this exists)
61+
(cb) => self.object.new('unixfs-dir', cb)
62+
]
63+
64+
if (typeof addDefaultAssets === 'function') {
65+
tasks.push(
66+
(cb) => addDefaultAssets(self, opts.log, cb)
67+
)
68+
}
69+
70+
parallel(tasks, (err) => {
71+
if (err) {
72+
return cb(err)
73+
}
74+
75+
cb(null, true)
76+
})
5977
}
6078
], callback)
6179
}

0 commit comments

Comments
 (0)