Summary: struct dirent.d_type is not a mask
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Tomash Brechko <> 2010-09-29 
04:18:02 PDT ---
In phobos/std/file.d:

version(Posix) struct DirEntry
    bool isdir() const
        return (d_type & DT_DIR) != 0;

    bool isfile() const
        return (d_type & DT_REG) != 0;

But struct dirent.d_type is not a mask (unlike struct stat.st_mode), it's a
plain value, and should be compared (d_type == DT_DIR) and (d_type == DT_REG)
respectively.  To test, compile the following:

// dir.d
import std.file;
import std.stdio;

main(string[] args)
  foreach (string name; dirEntries(args[1], SpanMode.depth))

and then do:

$ mkdir /tmp/test
$ mksock /tmp/test/sock
$ ./dir /tmp/test
std.file.fileexcept...@std/file.d(1066): /tmp/test/sock: Not a directory
./dir() [0x804d71f]
./dir() [0x804daf8]
./dir() [0x804d95f]
./dir() [0x8049750]
./dir() [0x804d9ea]
./dir() [0x8049683]
./dir() [0x80494ef]
./dir() [0x804bf06]
./dir() [0x804be60]
./dir() [0x804bf4a]
./dir() [0x804be60]
./dir() [0x804be06]
/lib/ [0x3edbb6]
./dir() [0x8049401]

See it tries to descend into /tmp/test/sock.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to