Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix it so that DirEntry on POSIX only calls lstat once #9768

Open
dlangBugzillaToGithub opened this issue Dec 13, 2018 · 0 comments
Open

Fix it so that DirEntry on POSIX only calls lstat once #9768

dlangBugzillaToGithub opened this issue Dec 13, 2018 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

issues.dlang (@jmdavis) reported this on 2018-12-13T23:37:32Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=19484

Description

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.
@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants