Skip to content

Commit

Permalink
Throw ENOTDIR error when dir doesn't exist for makeFile async
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jun 20, 2019
1 parent 2d17ed5 commit 07ca291
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/ensure/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ const pathExists = require('../path-exists').pathExists

function createFile (file, callback) {
function makeFile () {
fs.writeFile(file, '', err => {
const dir = path.dirname(file)

fs.stat(dir, (err, stats) => {
if (err) return callback(err)
callback()
if (!stats.isDirectory()) {
// This is just to cause an internal ENOTDIR error to be thrown
fs.readdir(dir, err => {
if (err) return callback(err)
})
} else {
fs.writeFile(file, '', err => {
if (err) return callback(err)
callback()
})
}
})
}

Expand Down

0 comments on commit 07ca291

Please sign in to comment.