Node: fs.lstat() of a linked directory returns `false` from `stat.isDirectory()`

Created on 4 Jan 2019  路  5Comments  路  Source: nodejs/node

  • Version: v10.11.0
  • Platform: Darwin kuma 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64
  • Subsystem: fs

It appears that fs.lstat() has regressed, such stats.isDirectory() will always return false regardless if the path is an actual directory.

screenshot example:
screen shot 2019-01-04 at 12 25 41 pm

fs question

All 5 comments

Your example seems to be working as intended: The difference between lstat and stat is that lstat returns information about the link itself, if the path points to one, so you get information about ./x, not ../x. And ./x is a symbolic link, not a directory.

@addaleax since fstat is for a descriptor, and stat is not for a link, how do you check if a symlink is a dir using fs?

@avoidwork You don鈥檛 want fstat if you don鈥檛 have a file descriptor. Just using plain stat should do, if I understand you correctly.

i need more coffee; i didn't realize lstat was intended for the link itself, i erroneously assumed it was a stat for the linked object :D

screen shot 2019-01-04 at 12 40 26 pm

Was this page helpful?
0 / 5 - 0 ratings