fs.readdir() does not report ENOTDIR error on Windows #1869

jankolkmeier opened this Issue Oct 12, 2011 · 5 comments

5 participants


node.exe v0.5.9.

Using fs.readdir() with as parameter a path to a file does not produce the "ENOTDIR" error as expected. Instead an "UNKNOWN" error is reported.

Reproduce the error:

fs.readdir("path/to/a/file.txt", function(err, files) {
    if (err) throw err;

This currently breaks the watch-tree module, specifically this file (line 148):

EDIT: Probably more errors than just the ENOTDIR error are affected.

@bnoordhuis bnoordhuis added a commit that referenced this issue Oct 12, 2011
@bnoordhuis bnoordhuis test: add test for #1869
fs.readdir() on file should raise ENOTDIR, not UNKNOWN.
@bnoordhuis bnoordhuis added a commit that closed this issue Oct 12, 2011
@bnoordhuis bnoordhuis uv: upgrade to 25a177a
Fixes #1869.
@bnoordhuis bnoordhuis reopened this Oct 12, 2011
Node.js Foundation member

Fixed on UNIX, fix for Windows pending.

@aikar aikar added a commit that referenced this issue Oct 12, 2011
@aikar aikar Merge branch 'master' of github:joyent/node into forkperfincrease
* 'master' of github:joyent/node:
  Revert some changes made in 12486a6
  Remove uname and git-rev detection from http_simple.js
  Upgrade libuv to c903bc3
  docs: fix child_process.send() example
  uv: upgrade to 25a177a
  test: add test for #1869
  Remove --use-legacy switch from --help section.
  introduce node cluster
  fix simple/test-fs-utimes.js on windows
  Add throughput benchmark
  fs.watch documentation

@bnoordhuis Have an update on this bug? I don't have a Windows machine I can test on.

Node.js Foundation member

Windows will just tell us that the file does not exist, so distinguishing ENOENT from ENOTDIR is impossible here.

(I can think of a trick where we'd open the root dir first, and then work our way towards the final file using the windows equivalent of openat(). However it'd have too much of a negative performance impact.)


OP seems to be fixed:

> fs.readdirSync('Release\\node.exe')
Error: ENOTDIR, not a directory 'c:\node-v0.8.15\Release\node.exe'
    at Object.fs.readdirSync (fs.js:500:18)
    at repl:1:5
    at REPLServer.self.eval (repl.js:109:21)
    at Interface.<anonymous> (repl.js:248:12)
    at Interface.EventEmitter.emit (events.js:96:17)
    at Interface._onLine (readline.js:200:10)
    at Interface._line (readline.js:518:8)
    at Interface._ttyWrite (readline.js:736:14)
    at ReadStream.onkeypress (readline.js:97:10)
    at ReadStream.EventEmitter.emit (events.js:126:20)
> fs.readdir('Release\\node.exe', console.error)
> { [Error: ENOTDIR, readdir 'c:\node-v0.8.15\Release\node.exe']
  errno: 27,
  code: 'ENOTDIR',
  path: 'c:\\node-v0.8.15\\Release\\node.exe' }
Node.js Foundation member

Sorry, I was thinking too far ahead :-)

In this case windows and linux actually behave the same. The difference is here:

// windows
fs.readFileSync('c:\\file-that-exists\\bogus') // throws ENOENT
// unix
fs.readFileSync('/file-that-exists/bogus') // throws ENOTDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment