runtime: Directory.EnumerateDirectories doesn't return directory list on rhel7.2

From @jainaashish on April 7, 2018 0:18

I’ve created a simple application to demonstrate the issue where Directory.EnumerateDirectories api doesn’t return the list of child directories on rhel 7.2, although it works fine on Windows or Ubuntu.

Sample Project - https://github.com/jainaashish/CoreClrIssue/tree/master/EnumerateDirectoriesIssue/EnumerateDirectoriesIssue

Copied from original issue: dotnet/coreclr#17465

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (24 by maintainers)

Most upvoted comments

@anipik I think we can set this issue aside now. It is fully understood and fixed.

For future reference, this only reproes on XFS if ftype=0, eg in my case:

$ xfs_info /
meta-data=/dev/sda2              isize=256    agcount=4, agsize=1934016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=7736064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=3777, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

This is set at the time the volume is created with mkfs.

The problem is we are seeing directories as files. We call readdir and check whether the d_type is DT_DIR.

The issue is that these machines have XFS file system, on which readdir returns a d_type of DT_UNKNOWN for both files and directories.

In 2.0 encountering DT_UNKNOWN we then fell back to calling lstat to find out whether it’s a directory - as the docs for readdir say we should. https://github.com/dotnet/corefx/blob/release/2.0.0/src/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs#L614-L630

In 2.1 we only do this for DT_LNK. https://github.com/dotnet/corefx/blob/AddAlpine3.8/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEntry.Unix.cs#L47

@Anipik can you please make this your first priority as we need to know whether there is a 2.1 bug.