Permalink
Browse files

fix: .rmdir() should throw ENOTEMPTY for non empty dirs (closes #3)

  • Loading branch information...
1 parent 64fb0cd commit 50f54e9551d9ece5578213564268021d4976db26 @eldargab committed Feb 22, 2013
Showing with 6 additions and 8 deletions.
  1. +3 −0 lib/fake-fs.js
  2. +3 −8 test/fake-fs.js
View
@@ -117,6 +117,9 @@ Fs.prototype.rmdirSync = function (path) {
var item = this._get(path)
if (!item.isDirectory()) throw FsError('ENOTDIR')
+ var hasChildren = item.childs && Object.keys(item.childs).length
+ if (hasChildren) throw FsError('ENOTEMPTY')
+
var parent = this._get(dirname(path))
updateTimes(parent)
this._rem(path)
View
@@ -232,17 +232,12 @@ describe('Fake FS', function () {
fs.existsSync('a/b').should.be.false
})
- it('Should remove an existing direcory, its subdirectories and files', function () {
+ it('Should throw ENOTEMPTY for non empty dirs', function () {
fs.dir('a/b/c')
- fs.file('a/b/file.txt')
- fs.rmdirSync('a/b')
-
- fs.existsSync('a/b/c').should.be.false
- fs.existsSync('a/b/file.txt').should.be.false
- fs.existsSync('a/b').should.be.false
+ fs.rmdir('a/b', cb)
- fs.existsSync('a').should.be.true
+ cb.error('ENOTEMPTY')
})
it('Should throw an ENOTDIR error on file', function () {

0 comments on commit 50f54e9

Please sign in to comment.