D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1635 - DirEntry.isfile() and DirEntry.isdir() broken
Summary: DirEntry.isfile() and DirEntry.isdir() broken
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: Other Linux
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-03 16:17 UTC by Marcin Kuszczak
Modified: 2014-02-24 16:00 UTC (History)
2 users (show)

See Also:


Attachments
test file with only few functions from std.file (3.70 KB, text/plain)
2007-11-04 16:29 UTC, Marcin Kuszczak
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Marcin Kuszczak 2007-11-03 16:17:36 UTC
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);
}
Comment 1 Brad Roberts 2007-11-04 01:28:38 UTC
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?
Comment 2 Marcin Kuszczak 2007-11-04 16:26:47 UTC
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.
Comment 3 Marcin Kuszczak 2007-11-04 16:29:15 UTC
Created attachment 201 [details]
test file with only few functions from std.file
Comment 4 Lutger 2008-10-07 05:59:44 UTC
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.







 
Comment 5 Andrei Alexandrescu 2010-09-25 17:39:04 UTC
Can't reproduce.
Comment 6 Jonathan M Davis 2010-09-25 18:09:50 UTC
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.