mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Remove unused fsUtils.isFile()
This commit is contained in:
parent
f00691529a
commit
cad1d5764b
@ -1,27 +1,4 @@
|
|||||||
fs = require('fs')
|
|
||||||
_ = require('lodash')
|
_ = require('lodash')
|
||||||
async = require('async')
|
|
||||||
|
|
||||||
exports.isValidPath = (p) ->
|
exports.isValidPath = (p) ->
|
||||||
return _.isString(p)
|
return _.isString(p)
|
||||||
|
|
||||||
exports.isFile = (file, outerCallback) ->
|
|
||||||
async.waterfall([
|
|
||||||
|
|
||||||
# Check if the file exists
|
|
||||||
(callback) ->
|
|
||||||
fs.exists file, (exists) ->
|
|
||||||
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())
|
|
||||||
|
|
||||||
], outerCallback)
|
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
expect = require('chai').expect
|
expect = require('chai').expect
|
||||||
_ = require('lodash')
|
|
||||||
mockFs = require('mock-fs')
|
|
||||||
|
|
||||||
fsUtils = require('./fs-utils')
|
fsUtils = require('./fs-utils')
|
||||||
|
|
||||||
PATHS =
|
|
||||||
file:
|
|
||||||
name: '/tmp/file1'
|
|
||||||
contents: 'File1 contents'
|
|
||||||
directory:
|
|
||||||
name: '/tmp/dir'
|
|
||||||
contents: mockFs.directory()
|
|
||||||
|
|
||||||
describe 'FsUtils:', ->
|
describe 'FsUtils:', ->
|
||||||
|
|
||||||
describe '#isValidPath()', ->
|
describe '#isValidPath()', ->
|
||||||
@ -36,32 +25,3 @@ describe 'FsUtils:', ->
|
|||||||
'./file/../file2'
|
'./file/../file2'
|
||||||
]
|
]
|
||||||
expect(fsUtils.isValidPath(validPath)).to.be.true
|
expect(fsUtils.isValidPath(validPath)).to.be.true
|
||||||
|
|
||||||
describe '#isFile()', ->
|
|
||||||
|
|
||||||
beforeEach ->
|
|
||||||
mockFsOptions = {}
|
|
||||||
for key, value of PATHS
|
|
||||||
mockFsOptions[value.name] = value.contents
|
|
||||||
mockFs(mockFsOptions)
|
|
||||||
|
|
||||||
afterEach ->
|
|
||||||
mockFs.restore()
|
|
||||||
|
|
||||||
it 'should return true for files', (done) ->
|
|
||||||
fsUtils.isFile PATHS.file.name, (error, isFile) ->
|
|
||||||
expect(error).to.not.exist
|
|
||||||
expect(isFile).to.be.true
|
|
||||||
done()
|
|
||||||
|
|
||||||
it 'should return false if file doesn\'t exists', (done) ->
|
|
||||||
fsUtils.isFile '/nonexistentfile', (error, isFile) ->
|
|
||||||
expect(error).to.not.exist
|
|
||||||
expect(isFile).to.be.false
|
|
||||||
done()
|
|
||||||
|
|
||||||
it 'should return false if path is a directory', (done) ->
|
|
||||||
fsUtils.isFile PATHS.directory.name, (error, isFile) ->
|
|
||||||
expect(error).to.not.exist
|
|
||||||
expect(isFile).to.be.false
|
|
||||||
done()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user