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

Commit 058c674

Browse files
richardschneiderdaviddias
authored andcommitted
fix(files.add): directory with odd name (#1155)
1 parent 279af78 commit 058c674

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/cli/commands/files/add.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,20 @@ module.exports = {
206206
}
207207
const ipfs = argv.ipfs
208208

209-
let list = []
209+
let list
210210
waterfall([
211-
(next) => glob(path.join(inPath, '/**/*'), next),
211+
(next) => {
212+
if (fs.statSync(inPath).isDirectory()) {
213+
return glob('**/*', { cwd: inPath }, next)
214+
}
215+
next(null, [])
216+
},
212217
(globResult, next) => {
213-
list = globResult.length === 0 ? [inPath] : globResult
214-
218+
if (globResult.length === 0) {
219+
list = [inPath]
220+
} else {
221+
list = globResult.map((f) => inPath + '/' + f)
222+
}
215223
getTotalBytes(inPath, argv.recursive, next)
216224
},
217225
(totalBytes, next) => {

test/cli/files.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ describe('files', () => runOnAndOff((thing) => {
154154
})
155155
})
156156

157+
it('add directory with odd name', function () {
158+
this.timeout(30 * 1000)
159+
const expected = [
160+
'added QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o odd-name-[v0]/odd name [v1]/hello',
161+
'added QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ odd-name-[v0]/odd name [v1]',
162+
'added QmXJGoo27bg7ExNAtr9vRcivxDwcfHtkxatGno9HrUdR16 odd-name-[v0]'
163+
]
164+
165+
return ipfs('files add -r test/fixtures/odd-name-[v0]')
166+
.then((out) => {
167+
expect(out).to.eql(expected.join('\n') + '\n')
168+
})
169+
})
170+
157171
it('add and wrap with a directory', function () {
158172
this.timeout(30 * 1000)
159173

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

0 commit comments

Comments
 (0)