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

PathUtility.HasExtension doesn't correctly consider case sensitivity of file system #47705

Open
Youssef1313 opened this issue Mar 18, 2025 · 2 comments
Labels
Area-CLI untriaged Request triage from a team member

Comments

@Youssef1313
Copy link
Member

var comparison = StringComparison.Ordinal;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
comparison = StringComparison.OrdinalIgnoreCase;
}

Only Windows is considered case insensitive, but looks like MacOS is also case insensitive.

I very much recall I have seen code somewhere in dotnet org that tries to create a dummy file, and then calls File.Exists with different casing to determine whether the file system is case sensitive and handle some potential edge cases, but I can't recall where that is.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Mar 18, 2025
@KalleOlaviNiemitalo
Copy link
Contributor

On macOS, one can create a HFS file system as case-sensitive or case-insensitive. Not sure about APFS.

On Windows, individual directories in NTFS can be set as case-sensitive or case-insensitive; and the case folding table is stored in the file system so it might not match the version of Unicode in the operating system. Not sure about ReFS.

@KalleOlaviNiemitalo
Copy link
Contributor

I very much recall I have seen code somewhere in dotnet org that tries to create a dummy file, and then calls File.Exists with different casing to determine whether the file system is case sensitive and handle some potential edge cases, but I can't recall where that is.

There is code like that at https://github.com/dotnet/msbuild/blob/bcc2dc6a6509ffb63f1253a9bbbaaa233bd53a50/src/Shared/FileUtilities.cs#L69-L91 and the comment there links to https://github.com/dotnet/runtime/blob/73ba11f3015216b39cb866d9fb7d3d25e93489f2/src/libraries/Common/src/System/IO/PathInternal.CaseSensitivity.cs#L41-L59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants