Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
jankolkmeier opened this Issue · 5 comments

5 participants

@jankolkmeier

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):
https://github.com/tafa/node-watch-tree/blob/master/lib/watchers/stat.js

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

@bnoordhuis bnoordhuis referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@bnoordhuis bnoordhuis referenced this issue from a commit
@bnoordhuis bnoordhuis test: add test for #1869
fs.readdir() on file should raise ENOTDIR, not UNKNOWN.
c82828e
@bnoordhuis bnoordhuis reopened this
@bnoordhuis
Owner

Fixed on UNIX, fix for Windows pending.

@aikar aikar referenced this issue from a commit
@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
52674f2
@japj japj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@japj japj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@japj japj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@japj japj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@trevnorris
Owner

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

@piscisaureus

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

@isaacs
Owner

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)
undefined
> { [Error: ENOTDIR, readdir 'c:\node-v0.8.15\Release\node.exe']
  errno: 27,
  code: 'ENOTDIR',
  path: 'c:\\node-v0.8.15\\Release\\node.exe' }
@piscisaureus

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
Something went wrong with that request. Please try again.