Bug 8291 – dirEntry cannot handle root directories + unhandled exception causes crash

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2012-06-24T10:03:00Z
Last change time
2013-12-19T02:34:26Z
Assigned to
nobody
Creator
mp81ss

Comments

Comment #0 by mp81ss — 2012-06-24T10:03:15Z
1) Wrong root handling api/params. To stat a root directory, the "GetFileAttributes" API must be used instead of "FindFirstFile". To stat all files in a root dir, "C:\*" must be passed to FindFirstFile. In all other cases, a path with [back]slash removed can be passed to "FindFirstFile". I know this in crazy, if you don't believe me, read CAREFULLY the FindFirstFile docs. P.S.: This should make you see that the dirEntries method may have some problems... 2) Crash The result of FindFirstFile is "enforced" in _init private method and NOT CAUGHT in the caller public method dirEntry, and this crashes the client app. It would be better to throw a FileException in _init and catch+rethrow it in dirEntry. Found on 2.059
Comment #1 by dlang-bugzilla — 2012-12-21T21:31:50Z
(In reply to comment #0) > 1) Wrong root handling api/params. > To stat a root directory, the "GetFileAttributes" API must be used instead of > "FindFirstFile". > To stat all files in a root dir, "C:\*" must be passed to FindFirstFile. > In all other cases, a path with [back]slash removed can be passed to > "FindFirstFile". > I know this in crazy, if you don't believe me, read CAREFULLY the FindFirstFile > docs. > P.S.: > This should make you see that the dirEntries method may have some problems... The following program works as expected, and prints the files/directories in the root of my C: drive: import std.stdio; import std.file; void main() { writeln(dirEntries(`C:\`, SpanMode.shallow)); } Can you clarify the problem? > 2) Crash > The result of FindFirstFile is "enforced" in _init private method and NOT > CAUGHT in the caller public method dirEntry, and this crashes the client app. > It would be better to throw a FileException in _init and catch+rethrow it in > dirEntry. So what is the exact problem? Isn't a FileException thrown in either case?
Comment #2 by mp81ss — 2013-12-19T02:34:26Z
Rechecked with Phobos 2.064.2, FIXED, (maybe fixed in earlier rev).