Make std.file.DirEntry._ensureStatDone safe

This commit is contained in:
Tomoya Tanjo 2014-10-09 19:04:18 +09:00
parent ddae9ae99d
commit 2bec7fc296

View file

@ -2274,12 +2274,16 @@ else version(Posix)
This is to support lazy evaluation, because doing stat's is This is to support lazy evaluation, because doing stat's is
expensive and not always needed. expensive and not always needed.
+/ +/
void _ensureStatDone() void _ensureStatDone() @safe
{ {
static auto trustedStat(in char[] path, stat_t* buf) @trusted
{
return stat(path.tempCString(), buf);
}
if(_didStat) if(_didStat)
return; return;
enforce(stat(_name.tempCString(), &_statBuf) == 0, enforce(trustedStat(_name, &_statBuf) == 0,
"Failed to stat file `" ~ _name ~ "'"); "Failed to stat file `" ~ _name ~ "'");
_didStat = true; _didStat = true;