[Issue 12391] DirEntries throws in foreach

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Mar 22 19:03:41 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=12391

--- Comment #5 from b2.temp at gmx.com ---
It seems to be by design. By hand it's possible to catch silently (e.g the
/srv/tftpboot folder on linux).

void scan(string root)
{
    foreach(DirEntry entry; dirEntries(root, SpanMode.shallow))
    {
        try
        {
            writeln(entry.name);
            if (entry.isDir) scan(entry.name);
        }
        catch (FileException fe) {continue;}
    }
}

void main()
{
    scan("/srv/");
}�

The error happens in "bool stepIn(string directory)�" (std.file) because the
folders are only put on a stack if they have a valid handle.

What could be done is to put them on the stack, always, and to test later, when
the stack is used if the handle of each item is valid, but then the control is
lost over when and why a problem happens. The iterator could even return a
DirEntry with a special flag (hasNoHandle) to denote that an error occured.

--


More information about the Digitalmars-d-bugs mailing list