andrej.mitrovich (@AndrejMitrovic) reported this on 2011-06-09T16:13:56Z
I can't officially classify this as a bug. Jonathan said it might be a good idea to put it here just so it doesn't get lost, and then we can later decide if it's a bug or if we should just be careful what we do.
Here's some buggy code which might throw an exception (if you're lucky!):
foreach (string entry; dirEntries(curdir, SpanMode.shallow))
{
if (entry.isdir)
{
foreach (string subentry; dirEntries(entry, SpanMode.shallow))
{
if (subentry.isdir)
{
chdir(rel2abs(subentry));
}
}
}
}
This might throw something like this:
std.file.FileException@std\file.d(1124): .\foo\bar.d: The system cannot find the path specified.
The problem is chdir will modify curdir, and dirEntries doesn't store 'curdir' internally as an absolute address, so calling chdir() screws up the behavior of dirEntries.
Notes
- Absolute paths are not a suitable solution for POSIX.
- The root cause of all confusion is that
DirEntry can implicitly convert to string.
andrej.mitrovich (@AndrejMitrovic) reported this on 2011-06-09T16:13:56Z
Notes
DirEntrycan implicitly convert tostring.