← Back to index
|
Original Bugzilla link
Bug 4955 – struct dirent.d_type is not a mask
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-09-29T04:18:00Z
Last change time
2013-02-26T09:42:32Z
Assigned to
andrei
Creator
tomash.brechko
Comments
Comment #0
by tomash.brechko — 2010-09-29T04:18:02Z
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; void main(string[] args) { foreach (string name; dirEntries(args[1], SpanMode.depth)) writeln(name); } and then do: $ mkdir /tmp/test $ mksock /tmp/test/sock $ ./dir /tmp/test std.file.FileException@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/libc.so.6(__libc_start_main+0xe6) [0x3edbb6] ./dir() [0x8049401] See it tries to descend into /tmp/test/sock.
Comment #1
by andrei — 2010-09-29T09:38:20Z
Thanks for the catch!
Comment #2
by andrei — 2013-02-26T08:58:04Z
The code has been changed since, and my OSX tests suggests this has been fixed. OK to close?
Comment #3
by tomash.brechko — 2013-02-26T09:42:32Z
Closing, the bug has been fixed a long time ago.