From 334873d3784e2baa2b19f8f69b5aade36715ba03 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 12 Nov 2020 12:00:36 +0000 Subject: [PATCH] fix: align behaviour between go and js for content without paths (#3385) Aligns behaviour between js and go when no path is present during an import - we now pass an empty string instead of `'unknown'`. --- packages/interface-ipfs-core/src/add-all.js | 22 +++++++++++++++++++ .../src/api/resources/files-regular.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/interface-ipfs-core/src/add-all.js b/packages/interface-ipfs-core/src/add-all.js index a0705810a8..bb3ea5a145 100644 --- a/packages/interface-ipfs-core/src/add-all.js +++ b/packages/interface-ipfs-core/src/add-all.js @@ -171,6 +171,28 @@ module.exports = (common, options) => { expect(root.cid.toString()).to.equal(fixtures.directory.cid) }) + it('should receive progress path as empty string when adding content without paths', async function () { + const content = (name) => fixtures.directory.files[name] + const progressSizes = {} + + const dirs = [ + content('pp.txt'), + content('holmes.txt'), + content('jungle.txt') + ] + + const total = { + '': dirs.reduce((acc, curr) => acc + curr.length, 0) + } + + const handler = (bytes, path) => { + progressSizes[path] = bytes + } + + await drain(ipfs.addAll(dirs, { progress: handler })) + expect(progressSizes).to.deep.equal(total) + }) + it('should receive file name from progress event', async () => { const receivedNames = [] function handler (p, name) { diff --git a/packages/ipfs-http-server/src/api/resources/files-regular.js b/packages/ipfs-http-server/src/api/resources/files-regular.js index af1bf6f400..b3d27bc688 100644 --- a/packages/ipfs-http-server/src/api/resources/files-regular.js +++ b/packages/ipfs-http-server/src/api/resources/files-regular.js @@ -260,7 +260,7 @@ exports.add = { multipart(request), async function * (source) { for await (const entry of source) { - currentFileName = entry.name || 'unknown' + currentFileName = entry.name || '' if (entry.type === 'file') { filesParsed = true