Skip to content

Commit 2348d32

Browse files
committed
Merge pull request #16 from noffle/bad_path
handles bad fs paths
2 parents f2cf541 + 82148a9 commit 2348d32

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ exports.import = (target, dagService, options, callback) => {
3030
// streamImporter(options.stream, callback)
3131
return callback(new Error('stream importer has not been built yet'))
3232
} else if (typeof target === 'string') {
33-
const stats = fs.statSync(target)
33+
var stats
34+
try {
35+
stats = fs.statSync(target)
36+
} catch (e) {
37+
return callback(e)
38+
}
3439
if (stats.isFile()) {
3540
fileImporter(target, callback)
3641
} else if (stats.isDirectory() && options.recursive) {

tests/test-import.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ describe('layout: importer', function () {
5353
done()
5454
})
5555

56+
it('import a bad path', (done) => {
57+
importer.import('/foo/bar/quux/a!wofjaeiwojfoiew', ds, function (err, stat) {
58+
expect(err).to.exist
59+
done()
60+
})
61+
})
62+
5663
it('import a small file', (done) => {
5764
importer.import(small, ds, function (err, stat) {
5865
expect(err).to.not.exist

0 commit comments

Comments
 (0)