Skip to content

Commit c604c47

Browse files
committed
Return constants in PathInternal.GetIsCaseSensitive() on mobile platforms
In particular on Android probing using I/O is slow and contributes to slow app startup. Fixes #54339
1 parent bbc3366 commit c604c47

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/libraries/Common/src/System/IO/PathInternal.CaseSensitivity.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,28 @@ internal static StringComparison StringComparison
3131
/// <summary>
3232
/// Determines whether the file system is case sensitive.
3333
/// </summary>
34+
private static bool GetIsCaseSensitive()
35+
{
36+
// Return a constant for mobile platforms without resorting to I/O
37+
if (OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS())
38+
return true;
39+
if (OperatingSystem.IsBrowser())
40+
return false;
41+
if (OperatingSystem.IsAndroid())
42+
return false;
43+
return GetIsCaseSensitiveByProbing();
44+
}
45+
46+
/// <summary>
47+
/// Determines whether the file system is case sensitive by creating a file in a temp folder and observing the result.
48+
/// </summary>
3449
/// <remarks>
3550
/// Ideally we'd use something like pathconf with _PC_CASE_SENSITIVE, but that is non-portable,
3651
/// not supported on Windows or Linux, etc. For now, this function creates a tmp file with capital letters
3752
/// and then tests for its existence with lower-case letters. This could return invalid results in corner
3853
/// cases where, for example, different file systems are mounted with differing sensitivities.
3954
/// </remarks>
40-
private static bool GetIsCaseSensitive()
55+
private static bool GetIsCaseSensitiveByProbing()
4156
{
4257
try
4358
{

0 commit comments

Comments
 (0)