Thread overview
[Issue 1635] New: DirEntry.isfile() and DirEntry.isdir() broken
Nov 03, 2007
d-bugmail
Nov 04, 2007
d-bugmail
Nov 04, 2007
d-bugmail
Nov 04, 2007
d-bugmail
Oct 07, 2008
d-bugmail
Sep 26, 2010
Jonathan M Davis
November 03, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1635

           Summary: DirEntry.isfile() and DirEntry.isdir() broken
           Product: D
           Version: 1.023
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: aarti@interia.pl


On my linux system following code gives for any filesystem point:
0 0
result. At least on linux DirEntry can not distinguish between file and
directory.

-----------------
import std.stdio;
import std.file;

void main(char[][] args) {
    bool callback(DirEntry* de) {
        writef(de.isfile, " ", de.isdir);
        return true;
    }
    listdir(args[1], &callback);
}


-- 

November 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1635


braddr@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla@digitalmars.com    |aarti@interia.pl




------- Comment #1 from braddr@puremagic.com  2007-11-04 01:28 -------
I can't reproduce this on my linux system.  I'm going to need more information to be able to do anything with this report.  I suggest copying the code from std/file.d into your test app (ie, create a standalone test case that doesn't need any (or at least fewer) imports).  Add some debug code to inspect the data closer.

Make sense?


-- 

November 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1635





------- Comment #2 from aarti@interia.pl  2007-11-04 16:26 -------
After some researching it seems that in this structure (from import
std.c.linux.linux):

struct dirent
    {
        uint d_ino;             // this is int on some linuxes
        off_t d_off;
        ushort d_reclen;
        ubyte d_type;           // this field isn't there on some linuxes
        char[256] d_name;
    }

field d_type is not set by readdir method.

In the same time isdir & isfile free functions works properly.

I have fresh installation of Ubuntu Gutsy 7.10.


-- 

November 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1635





------- Comment #3 from aarti@interia.pl  2007-11-04 16:29 -------
Created an attachment (id=201)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=201&action=view)
test file with only few functions from std.file


-- 

October 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1635





------- Comment #4 from lutger.blijdestijn@gmail.com  2008-10-07 05:59 -------
Same problem here. The readdir docs say that the dirent.d_type field is a bsd
extension, not part of the posix standard. The standalone isdir() and isfile()
functions use stat, so they are fine (but more costly.)

This also breaks DirEntries in 2.0 and functions depending on it.










-- 

October 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1635


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|aarti@interia.pl            |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1635


Andrei Alexandrescu <andrei@metalanguage.com> changed:

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


--- Comment #5 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-09-25 17:39:04 PDT ---
Can't reproduce.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1635


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #6 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-09-25 18:09:50 PDT ---
See also bug# 4929. Currently, on Linux/Posix, DirEntry use d_type from readdir to set its file type, and if you'll look at the man page for readdir, it specifically says that d_type is not supported by all file system types. DirEntry really should be using stat if d_type wasn't set properly. My patch in bug# 3848 makes it so that while it still uses d_type for the file type if it was set correctly, it uses stat instead of d_type if d_type is DT_UNKNOWN.

The only place that I'm sure that I've run into this problem (and consistently) is with /usr/share/zoneinfo, but I think that it's very nature makes it so that it's only going to fail under certain types of situations or on certain types of systems.

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