mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-19 03:06:29 +00:00
Get rid of fsUtils.isDirectory
This commit is contained in:
parent
f75d06b302
commit
5059bcb212
@ -2,7 +2,7 @@ expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
async = require('async')
|
||||
fs = require('fs')
|
||||
fsUtils = require('./fs-utils/fs-utils')
|
||||
fsPlus = require('fs-plus')
|
||||
rimraf = require('rimraf')
|
||||
dataPrefix = require('./data-prefix')
|
||||
settings = require('../settings')
|
||||
@ -57,7 +57,8 @@ describe 'DataPrefix:', ->
|
||||
dataPrefix.set(@prefix, callback)
|
||||
|
||||
(callback) =>
|
||||
fsUtils.isDirectory(@prefix, callback)
|
||||
fsPlus.isDirectory @prefix, (isDirectory) ->
|
||||
return callback(null, isDirectory)
|
||||
|
||||
(isDirectory, callback) ->
|
||||
expect(isDirectory).to.be.true
|
||||
|
@ -1,4 +1,5 @@
|
||||
fs = require('fs')
|
||||
fsPlus = require('fs-plus')
|
||||
path = require('path')
|
||||
rimraf = require('rimraf')
|
||||
fsUtils = require('./fs-utils/fs-utils')
|
||||
@ -110,8 +111,6 @@ exports.has = haltIfNoPrefix (key, callback) ->
|
||||
exports.remove = haltIfNoPrefix (key, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
|
||||
fsUtils.isDirectory keyPath, (error, isDirectory) ->
|
||||
return callback(error) if error?
|
||||
|
||||
fsPlus.isDirectory keyPath, (isDirectory) ->
|
||||
removeFunction = if isDirectory then rimraf else fs.unlink
|
||||
removeFunction(keyPath, callback)
|
||||
|
@ -1,6 +1,6 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
fsUtils = require('./fs-utils/fs-utils')
|
||||
fsPlus = require('fs-plus')
|
||||
mock = require('../../../tests/utils/mock')
|
||||
async = require('async')
|
||||
settings = require('../settings')
|
||||
@ -182,7 +182,8 @@ describe 'Data:', ->
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
fsUtils.isDirectory(directory.name, callback)
|
||||
fsPlus.isDirectory directory.name, (isDirectory) ->
|
||||
return callback(null, isDirectory)
|
||||
|
||||
(isDirectory, callback) ->
|
||||
expect(isDirectory).to.be.true
|
||||
|
@ -16,26 +16,3 @@ _ = require('lodash')
|
||||
#
|
||||
exports.isValidPath = (p) ->
|
||||
return _.isString(p)
|
||||
|
||||
# Check if path is directory
|
||||
#
|
||||
# @private
|
||||
#
|
||||
# @param {String} directory directory
|
||||
# @param {Function} callback callback(error, isDirectory)
|
||||
#
|
||||
# @example Is directory?
|
||||
# isDirectory '/usr/local/share', (error, isDirectory) ->
|
||||
# throw error if error?
|
||||
# console.log(isDirectory)
|
||||
# # True
|
||||
#
|
||||
# isDirectory '/Users/me/app.js', (error, isDirectory) ->
|
||||
# throw error if error?
|
||||
# console.log(isDirectory)
|
||||
# # False
|
||||
#
|
||||
exports.isDirectory = (directory, callback) ->
|
||||
fs.stat directory, (error, stats) ->
|
||||
return callback?(error) if error?
|
||||
return callback?(null, stats.isDirectory())
|
||||
|
@ -45,21 +45,3 @@ describe 'FsUtils:', ->
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
||||
it 'should return true if directory', (done) ->
|
||||
fsUtils.isDirectory FILESYSTEM.directory.name, (error, isDirectory) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isDirectory).to.be.true
|
||||
done()
|
||||
|
||||
it 'should return false if not a directory', (done) ->
|
||||
fsUtils.isDirectory FILESYSTEM.text.name, (error, isDirectory) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isDirectory).to.be.false
|
||||
done()
|
||||
|
||||
it 'should return an error if the path doesn\'t exists', (done) ->
|
||||
fsUtils.isDirectory '/nonexistantpath', (error, isDirectory) ->
|
||||
expect(error).to.exist
|
||||
expect(isDirectory).to.be.undefined
|
||||
done()
|
||||
|
@ -58,6 +58,7 @@
|
||||
"request-progress": "~0.3.1",
|
||||
"progress-bar": "~0.1.1",
|
||||
"progress": "~1.1.8",
|
||||
"user-home": "~1.1.0"
|
||||
"user-home": "~1.1.0",
|
||||
"fs-plus": "~2.3.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user