Node: mkdir no ERROR when parent is a file with native recursive option

Created on 12 Apr 2019  路  7Comments  路  Source: nodejs/node

On windows Node.js v10.x hangs when trying to mkdir in a path where the parent is a file.
(sorry tested only on appveyor and travis)

Node8 on windows errors with EEXIST
Node10 on non-windows errors ENOTDIR
Node10 on windows hangs NO error 馃樋

  • Version: v10.15.3
  • Platform: Windows
  • Subsystem: fs
const fs = require('fs')
fs.writeFileSync('./test2.txt', '')
fs.mkdirSync('./test2.txt/sub/dir', {
    recursive: true
})

See hanging test on travis https://travis-ci.org/sindresorhus/make-dir
Related PR that adds test to make-dir https://github.com/sindresorhus/make-dir/pull/15

confirmed-bug fs

Most helpful comment

@targos if no one else has a moment to dig into this, I can try to tackle it early next week.

PR: https://github.com/nodejs/node/pull/27207

All 7 comments

I tested a bit more on appveyor and now I am not 100% sure if it might be a make-dir issue

Update, I think it only happens with the callback, mkdirSync I believe is fine (the example above).
This should hang:

  const fs = require('fs');
  fs.writeFileSync('./test2.txt', '');
  fs.mkdir('./test2.txt/sub/dir/dir/dir', {
    recursive: true
  }, function() {
    console.log('never calls back')
  });

Confirmed on my Windows PC:

> fs.mkdirSync('package.json/a/b', { recursive: true })
Thrown:
{ Error: EEXIST: file already exists, mkdir 'package.json/a/b'
    at Object.mkdirSync (fs.js:773:3)
  errno: -4075,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: 'package.json/a/b' }
> fs.mkdir('package.json/a/b', { recursive: true }, console.log)
undefined
> var p = fs.promises.mkdir('package.json/a/b', { recursive: true })
undefined
> p
Promise { <pending> }

It's actually going into an infinite loop (the process uses 100% of my CPU)

/cc @nodejs/fs @bcoe

@targos if no one else has a moment to dig into this, I can try to tackle it early next week.

@targos if no one else has a moment to dig into this, I can try to tackle it early next week.

PR: https://github.com/nodejs/node/pull/27207

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Icemic picture Icemic  路  3Comments

cong88 picture cong88  路  3Comments

jmichae3 picture jmichae3  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

dfahlander picture dfahlander  路  3Comments