Get rid of fsUtils.isDirectory

This commit is contained in:
Juan Cruz Viotti 2014-12-08 11:02:23 -04:00
parent f75d06b302
commit 5059bcb212
6 changed files with 10 additions and 49 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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())

View File

@ -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()

View File

@ -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"
}
}