[Issue 2838] std.file.rmdirRecurse fails
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Apr 16 18:05:21 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2838
------- Comment #3 from graham.stjack at internode.on.net 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
(DT_UNKNOWN)?
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) {
ensureStatDone;
}
}
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 * std.date.TicksPerSecond;
_lastAccessTime = cast(d_time)statbuf.st_atime *
std.date.TicksPerSecond;
_lastWriteTime = cast(d_time)statbuf.st_mtime * std.date.TicksPerSecond;
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
like...
--
More information about the Digitalmars-d-bugs
mailing list