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

Commit 0036314

Browse files
committed
importing multiple roots yields an error
1 parent 01d8583 commit 0036314

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/builder/create-build-stream.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ module.exports = function createBuildStream (createStrategy, ipldResolver, flush
1414
options.highWaterMark,
1515
(err) => {
1616
if (err) {
17-
return source.end(err)
17+
source.end(err)
18+
return // early
1819
}
1920

20-
flushTree(files, ipldResolver, source, () => {
21-
source.end()
22-
})
21+
flushTree(files, ipldResolver, source, source.end)
2322
}
2423
)
2524

src/importer/flush-tree.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ module.exports = (files, ipldResolver, source, callback) => {
1313
// 1) convert files to a tree
1414
const fileTree = createTree(files)
1515

16+
if (Object.keys(fileTree).length > 1) {
17+
callback(new Error('detected more than one root'))
18+
return
19+
}
20+
1621
if (Object.keys(fileTree).length === 0) {
1722
return callback()// no dirs to be created
1823
}

test/test-importer.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = (repo) => {
170170
ipldResolver = new IPLDResolver(bs)
171171
})
172172

173-
it('bad input', (done) => {
173+
it('fails on bad input', (done) => {
174174
pull(
175175
pull.values([{
176176
path: '200Bytes.txt',
@@ -184,6 +184,27 @@ module.exports = (repo) => {
184184
)
185185
})
186186

187+
it('fails on more than one root', (done) => {
188+
pull(
189+
pull.values([
190+
{
191+
path: '/beep/200Bytes.txt',
192+
content: pull.values([smallFile])
193+
},
194+
{
195+
path: '/boop/200Bytes.txt',
196+
content: pull.values([smallFile])
197+
}
198+
]),
199+
importer(ipldResolver, options),
200+
pull.onEnd((err) => {
201+
expect(err).to.exist
202+
expect(err.message).to.be.eql('detected more than one root')
203+
done()
204+
})
205+
)
206+
})
207+
187208
it('small file (smaller than a chunk)', (done) => {
188209
pull(
189210
pull.values([{

0 commit comments

Comments
 (0)