mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 16:36:24 +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')
|
_ = require('lodash')
|
||||||
async = require('async')
|
async = require('async')
|
||||||
fs = require('fs')
|
fs = require('fs')
|
||||||
fsUtils = require('./fs-utils/fs-utils')
|
fsPlus = require('fs-plus')
|
||||||
rimraf = require('rimraf')
|
rimraf = require('rimraf')
|
||||||
dataPrefix = require('./data-prefix')
|
dataPrefix = require('./data-prefix')
|
||||||
settings = require('../settings')
|
settings = require('../settings')
|
||||||
@ -57,7 +57,8 @@ describe 'DataPrefix:', ->
|
|||||||
dataPrefix.set(@prefix, callback)
|
dataPrefix.set(@prefix, callback)
|
||||||
|
|
||||||
(callback) =>
|
(callback) =>
|
||||||
fsUtils.isDirectory(@prefix, callback)
|
fsPlus.isDirectory @prefix, (isDirectory) ->
|
||||||
|
return callback(null, isDirectory)
|
||||||
|
|
||||||
(isDirectory, callback) ->
|
(isDirectory, callback) ->
|
||||||
expect(isDirectory).to.be.true
|
expect(isDirectory).to.be.true
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
fs = require('fs')
|
fs = require('fs')
|
||||||
|
fsPlus = require('fs-plus')
|
||||||
path = require('path')
|
path = require('path')
|
||||||
rimraf = require('rimraf')
|
rimraf = require('rimraf')
|
||||||
fsUtils = require('./fs-utils/fs-utils')
|
fsUtils = require('./fs-utils/fs-utils')
|
||||||
@ -110,8 +111,6 @@ exports.has = haltIfNoPrefix (key, callback) ->
|
|||||||
exports.remove = haltIfNoPrefix (key, callback) ->
|
exports.remove = haltIfNoPrefix (key, callback) ->
|
||||||
keyPath = constructPath(key)
|
keyPath = constructPath(key)
|
||||||
|
|
||||||
fsUtils.isDirectory keyPath, (error, isDirectory) ->
|
fsPlus.isDirectory keyPath, (isDirectory) ->
|
||||||
return callback(error) if error?
|
|
||||||
|
|
||||||
removeFunction = if isDirectory then rimraf else fs.unlink
|
removeFunction = if isDirectory then rimraf else fs.unlink
|
||||||
removeFunction(keyPath, callback)
|
removeFunction(keyPath, callback)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
expect = require('chai').expect
|
expect = require('chai').expect
|
||||||
_ = require('lodash')
|
_ = require('lodash')
|
||||||
fsUtils = require('./fs-utils/fs-utils')
|
fsPlus = require('fs-plus')
|
||||||
mock = require('../../../tests/utils/mock')
|
mock = require('../../../tests/utils/mock')
|
||||||
async = require('async')
|
async = require('async')
|
||||||
settings = require('../settings')
|
settings = require('../settings')
|
||||||
@ -182,7 +182,8 @@ describe 'Data:', ->
|
|||||||
async.waterfall [
|
async.waterfall [
|
||||||
|
|
||||||
(callback) ->
|
(callback) ->
|
||||||
fsUtils.isDirectory(directory.name, callback)
|
fsPlus.isDirectory directory.name, (isDirectory) ->
|
||||||
|
return callback(null, isDirectory)
|
||||||
|
|
||||||
(isDirectory, callback) ->
|
(isDirectory, callback) ->
|
||||||
expect(isDirectory).to.be.true
|
expect(isDirectory).to.be.true
|
||||||
|
@ -16,26 +16,3 @@ _ = require('lodash')
|
|||||||
#
|
#
|
||||||
exports.isValidPath = (p) ->
|
exports.isValidPath = (p) ->
|
||||||
return _.isString(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 ->
|
afterEach ->
|
||||||
mock.fs.restore()
|
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",
|
"request-progress": "~0.3.1",
|
||||||
"progress-bar": "~0.1.1",
|
"progress-bar": "~0.1.1",
|
||||||
"progress": "~1.1.8",
|
"progress": "~1.1.8",
|
||||||
"user-home": "~1.1.0"
|
"user-home": "~1.1.0",
|
||||||
|
"fs-plus": "~2.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user