-
Notifications
You must be signed in to change notification settings - Fork 5.3k
FileSystem.Exists.Unix: eliminate a stat call when checking a non-existing file/directory. #55210
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
Conversation
…sting file/directory. When checking for a directory, we can use `stat`, there is no need to make an `lstat` call. When checking for a file, use `lstat` which will give us what we need in most cases. Only when it is a link, we need to call `stat` to check if the final target is not a directory.
|
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsWhen checking for a directory, we can use When checking for a file, use @adamsitnik @stephentoub ptal.
|
| ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR); | ||
| if ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFLNK) | ||
| { | ||
| if (Interop.Sys.Stat(fullPath, out fileinfo) < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that, when the target is a symbolic link, we're now making two calls instead of one.
So, this is an improvement when the API is used more to check for non-existing files, than it is used against links.
jozkee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise; lgtm, thanks.
| // Something exists at this path. If the caller is asking for a directory, return true if it's | ||
| // a directory and false for everything else. If the caller is asking for a file, return false for | ||
| // a directory and true for everything else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please preserve this comment and extend it to reflect that symbolic links need to be stat'd in order to discard that they are not targeting a directory?
When checking for a directory, we can use
stat, there is no need to make anlstatcall.When checking for a file, use
lstatwhich will give us what we need in most cases.Only when it is a link, we need to call
statto check if the final target is not a directory.@adamsitnik @stephentoub ptal.