[Issue 4929] New: DirEntry does not always report correct type of file on linux

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 23 19:58:12 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4929

           Summary: DirEntry does not always report correct type of file
                    on linux
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-09-23 19:57:31 PDT ---
Okay, if you run this program

import std.file;
import std.stdio;

void main()
{
    foreach(DirEntry dentry; dirEntries("/usr/share/zoneinfo", SpanMode.depth))
    {
        if(dentry.isfile)
            writefln("file: %s", dentry.name);
        else if(dentry.isdir)
            writefln("dir: %s", dentry.name);
        else
            writefln("other: %s", dentry.name);
    }
}


on a Linux box, you get this output (or something very close to it):

other: /usr/share/zoneinfo/GB
other: /usr/share/zoneinfo/NZ
other: /usr/share/zoneinfo/US
other: /usr/share/zoneinfo/CET
other: /usr/share/zoneinfo/EET
other: /usr/share/zoneinfo/EST
other: /usr/share/zoneinfo/GMT
other: /usr/share/zoneinfo/HST
other: /usr/share/zoneinfo/Etc
other: /usr/share/zoneinfo/MET
other: /usr/share/zoneinfo/MST
other: /usr/share/zoneinfo/PRC
other: /usr/share/zoneinfo/ROC
other: /usr/share/zoneinfo/ROK
other: /usr/share/zoneinfo/UCT
other: /usr/share/zoneinfo/UTC
other: /usr/share/zoneinfo/WET
other: /usr/share/zoneinfo/Asia
other: /usr/share/zoneinfo/Cuba
other: /usr/share/zoneinfo/GMT0
other: /usr/share/zoneinfo/Eire
other: /usr/share/zoneinfo/Iran
other: /usr/share/zoneinfo/W-SU
other: /usr/share/zoneinfo/Arctic
other: /usr/share/zoneinfo/Zulu
other: /usr/share/zoneinfo/Canada
other: /usr/share/zoneinfo/Brazil
other: /usr/share/zoneinfo/America
other: /usr/share/zoneinfo/Universal
other: /usr/share/zoneinfo/Europe
other: /usr/share/zoneinfo/Pacific
other: /usr/share/zoneinfo/Iceland
other: /usr/share/zoneinfo/iso3166.tab
other: /usr/share/zoneinfo/Chile
other: /usr/share/zoneinfo/GMT+0
other: /usr/share/zoneinfo/GMT-0
other: /usr/share/zoneinfo/Egypt
other: /usr/share/zoneinfo/Japan
other: /usr/share/zoneinfo/Portugal
other: /usr/share/zoneinfo/Libya
other: /usr/share/zoneinfo/Indian
other: /usr/share/zoneinfo/Israel
other: /usr/share/zoneinfo/posix
other: /usr/share/zoneinfo/right
other: /usr/share/zoneinfo/Hongkong
other: /usr/share/zoneinfo/Mexico
other: /usr/share/zoneinfo/Navajo
other: /usr/share/zoneinfo/Poland
other: /usr/share/zoneinfo/Jamaica
other: /usr/share/zoneinfo/EST5EDT
other: /usr/share/zoneinfo/Turkey
other: /usr/share/zoneinfo/GB-Eire
other: /usr/share/zoneinfo/zone.tab
other: /usr/share/zoneinfo/Antarctica
other: /usr/share/zoneinfo/Australia
other: /usr/share/zoneinfo/Kwajalein
other: /usr/share/zoneinfo/MST7MDT
other: /usr/share/zoneinfo/Singapore
other: /usr/share/zoneinfo/posixrules
other: /usr/share/zoneinfo/NZ-CHAT
other: /usr/share/zoneinfo/Factory
other: /usr/share/zoneinfo/Atlantic
other: /usr/share/zoneinfo/Greenwich
other: /usr/share/zoneinfo/Mideast
other: /usr/share/zoneinfo/PST8PDT
other: /usr/share/zoneinfo/CST6CDT
other: /usr/share/zoneinfo/Africa


Note that all of these files are in fact either directories or regular files. I
don't really know why, but my guess is that d_type is used from the
core.sys.posix.dirent.dirent for the file, and it deosn't work on all file
systems. I've tried it on 3 machines, with two different distros. All used
reiserfs for the / partition, so all of those were on reieserfs, and all
failed. I also tried it on one of my machienes by copying /usr/share/zoneinfo
onto my /home partition which uses jfs. It failed there too. Other directories
and files work just fine, so I don't know what's so special about zoneinfo.

It should be noted, however, that if you use std.isfile() or std.isdir(), it
works just fine - probably because those use stat.

I don't have a specific patch for this bug, but my patch for bug# 3848 does
apparently fix this bug (probably because it doesn't use d_type if it's
DT_UNKNOWN but instead uses stat in that case).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list