From 058c674f541a76f8b323f5f9193032b221b02d25 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Mon, 18 Dec 2017 20:49:39 +1300 Subject: [PATCH] fix(files.add): directory with odd name (#1155) --- src/cli/commands/files/add.js | 16 ++++++++++++---- test/cli/files.js | 14 ++++++++++++++ test/fixtures/odd-name-[v0]/odd name [v1]/hello | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/odd-name-[v0]/odd name [v1]/hello diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 3d2c2741ed..a41822b8db 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -206,12 +206,20 @@ module.exports = { } const ipfs = argv.ipfs - let list = [] + let list waterfall([ - (next) => glob(path.join(inPath, '/**/*'), next), + (next) => { + if (fs.statSync(inPath).isDirectory()) { + return glob('**/*', { cwd: inPath }, next) + } + next(null, []) + }, (globResult, next) => { - list = globResult.length === 0 ? [inPath] : globResult - + if (globResult.length === 0) { + list = [inPath] + } else { + list = globResult.map((f) => inPath + '/' + f) + } getTotalBytes(inPath, argv.recursive, next) }, (totalBytes, next) => { diff --git a/test/cli/files.js b/test/cli/files.js index 950d1510ce..5a36f52a4e 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -154,6 +154,20 @@ describe('files', () => runOnAndOff((thing) => { }) }) + it('add directory with odd name', function () { + this.timeout(30 * 1000) + const expected = [ + 'added QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o odd-name-[v0]/odd name [v1]/hello', + 'added QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ odd-name-[v0]/odd name [v1]', + 'added QmXJGoo27bg7ExNAtr9vRcivxDwcfHtkxatGno9HrUdR16 odd-name-[v0]' + ] + + return ipfs('files add -r test/fixtures/odd-name-[v0]') + .then((out) => { + expect(out).to.eql(expected.join('\n') + '\n') + }) + }) + it('add and wrap with a directory', function () { this.timeout(30 * 1000) diff --git a/test/fixtures/odd-name-[v0]/odd name [v1]/hello b/test/fixtures/odd-name-[v0]/odd name [v1]/hello new file mode 100644 index 0000000000..3b18e512db --- /dev/null +++ b/test/fixtures/odd-name-[v0]/odd name [v1]/hello @@ -0,0 +1 @@ +hello world