www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4929] New: DirEntry does not always report correct type of file on linux

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: jmdavisProg gmx.com



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.


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: -------
Sep 23 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4929


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4929


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



PST ---
This was fixed a long time ago.

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