------- Comment #3 from  2009-04-16 20:05 -------
I have looked into it some more, and it looks like setting of d_type is only
supported on some filesystems. I am using reiserfs, which I guess is a bit
unusual, and it could be that.

Yes, I just tried it with a vfat filesystem on a flash-stick, and d_type was
populated ok.

Can I suggest that, since the posix standard makes population of d_type (and
others) optional, we do something to handle the case where it is set to 0

Maybe the easiest thing to do is to modify std.file.DirEntry.init to be
something like:

   void init(string path, dirent *fd)
       immutable len = std.c.string.strlen(fd.d_name.ptr);
       name = std.path.join(path, fd.d_name[0 .. len].idup);
       d_type = fd.d_type;
       didstat = false;

       if (d_type == DT_UNKNOWN) {

or maybe defer it until isdir or isdile are called.

ensureStatDone would need to be modified to be something like:

   void ensureStatDone()
       if (didstat) return;
       enforce(core.sys.posix.sys.stat.stat(toStringz(name), &statbuf) == 0,
               "Failed to stat file `"~name~"'");
       _size = cast(ulong)statbuf.st_size;
       _creationTime = cast(d_time)statbuf.st_ctime *;
       _lastAccessTime = cast(d_time)statbuf.st_atime *;
       _lastWriteTime = cast(d_time)statbuf.st_mtime *;

       if (d_type == DT_UNKNOWN) {
           if (S_ISDIR(statbuf.st_mode)) {
               d_type = DT_DIR;
           else if (S_ISREG(statbuf.st_mode)) {
               d_type = DT_REG;

       didstat = true;

And of course std.file needs to be changed to use readdir_r too. If this
approach is acceptable to you, I could have a go at submitting a patch if you


Reply via email to