digitalmars.D.bugs - [Issue 19484] New: Fix it so that DirEntry on POSIX only calls lstat
- d-bugmail puremagic.com (27/27) Dec 13 2018 https://issues.dlang.org/show_bug.cgi?id=19484
https://issues.dlang.org/show_bug.cgi?id=19484 Issue ID: 19484 Summary: Fix it so that DirEntry on POSIX only calls lstat once Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: issues.dlang jmdavisProg.com On POSIX, DirEntry's constructor calls exists to verify that the file exists and then throws if it doesn't - which makes perfect sense until you look at what exists does. exists calls lstat, which is fine in and of itself, but calling exists means that that information is thrown away, whereas DirEntry then later calls lstat again when certain functions are called. It has the _didLStat member to keep track of whether it's called lstat yet, so it avoids calling it multiple times when the properties on it are used which require it, but it would be more efficient to just call lstat directly in the constructor and always save the result. If lstat fails, the exception can be thrown like it is now, but by checking the result of lstat directly rather than using exists, we remove the need for _didLStat, and we make it so that lstat is always called exactly once instead of being called once if the information from lstat isn't needed later or twice if it is. --
Dec 13 2018