mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Don't not send an error on isFile, even when the file doesn't exists
This commit is contained in:
parent
89bb0d0b21
commit
afe438ff82
@ -5,25 +5,23 @@ async = require('async')
|
||||
exports.isValidPath = (p) ->
|
||||
return _.isString(p)
|
||||
|
||||
exports.isFile = (file, callback) ->
|
||||
exports.isFile = (file, outerCallback) ->
|
||||
async.waterfall([
|
||||
|
||||
# Check if the file exists
|
||||
(callback) ->
|
||||
fs.exists file, (exists) ->
|
||||
if not exists
|
||||
|
||||
# Return false anyway to avoid confusions
|
||||
return callback(new Error('File doesn\'t exists'), false)
|
||||
|
||||
return callback(null, exists)
|
||||
|
||||
# Get file stats
|
||||
(exists, callback) ->
|
||||
if not exists
|
||||
return outerCallback(null, false)
|
||||
|
||||
fs.stat(file, callback)
|
||||
|
||||
# Check if it's a file
|
||||
(stats, callback) ->
|
||||
return callback(null, !!stats.isFile())
|
||||
|
||||
], callback)
|
||||
], outerCallback)
|
||||
|
@ -56,7 +56,7 @@ describe 'FsUtils', ->
|
||||
|
||||
it 'should return false if file doesn\'t exists', (done) ->
|
||||
fsUtils.isFile '/nonexistentfile', (error, isFile) ->
|
||||
expect(error).to.exist
|
||||
expect(error).to.not.exist
|
||||
expect(isFile).to.be.false
|
||||
done()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user