mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37: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) ->
|
exports.isValidPath = (p) ->
|
||||||
return _.isString(p)
|
return _.isString(p)
|
||||||
|
|
||||||
exports.isFile = (file, callback) ->
|
exports.isFile = (file, outerCallback) ->
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|
||||||
# Check if the file exists
|
# Check if the file exists
|
||||||
(callback) ->
|
(callback) ->
|
||||||
fs.exists file, (exists) ->
|
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)
|
return callback(null, exists)
|
||||||
|
|
||||||
# Get file stats
|
# Get file stats
|
||||||
(exists, callback) ->
|
(exists, callback) ->
|
||||||
|
if not exists
|
||||||
|
return outerCallback(null, false)
|
||||||
|
|
||||||
fs.stat(file, callback)
|
fs.stat(file, callback)
|
||||||
|
|
||||||
# Check if it's a file
|
# Check if it's a file
|
||||||
(stats, callback) ->
|
(stats, callback) ->
|
||||||
return callback(null, !!stats.isFile())
|
return callback(null, !!stats.isFile())
|
||||||
|
|
||||||
], callback)
|
], outerCallback)
|
||||||
|
@ -56,7 +56,7 @@ describe 'FsUtils', ->
|
|||||||
|
|
||||||
it 'should return false if file doesn\'t exists', (done) ->
|
it 'should return false if file doesn\'t exists', (done) ->
|
||||||
fsUtils.isFile '/nonexistentfile', (error, isFile) ->
|
fsUtils.isFile '/nonexistentfile', (error, isFile) ->
|
||||||
expect(error).to.exist
|
expect(error).to.not.exist
|
||||||
expect(isFile).to.be.false
|
expect(isFile).to.be.false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user