Bug 19484 – Fix it so that DirEntry on POSIX only calls lstat once

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-13T23:37:32Z
Last change time
2024-12-01T16:34:40Z
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: phobos#9768 →

Comments

Comment #0 by issues.dlang — 2018-12-13T23:37:32Z
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.
Comment #1 by robert.schadek — 2024-12-01T16:34:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9768 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB