Skip to content

Commit

Permalink
Make invariant/file-locking detection trim-safe
Browse files Browse the repository at this point in the history
Should fix #72330.
  • Loading branch information
MichalStrehovsky authored Jul 17, 2022
1 parent 3ea30ed commit 5982087
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,8 @@ public static string GetDistroVersionString()
}
}

private static readonly Lazy<bool> m_isInvariant = new Lazy<bool>(() => GetStaticNonPublicBooleanPropertyValue("System.Globalization.GlobalizationMode", "Invariant"));

private static bool GetStaticNonPublicBooleanPropertyValue(string typeName, string propertyName)
{
if (Type.GetType(typeName)?.GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Static)?.GetMethod is MethodInfo mi)
{
return (bool)mi.Invoke(null, null);
}

return false;
}
private static readonly Lazy<bool> m_isInvariant = new Lazy<bool>(()
=> (bool?)Type.GetType("System.Globalization.GlobalizationMode")?.GetProperty("Invariant", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true);

private static readonly Lazy<Version> m_icuVersion = new Lazy<Version>(GetICUVersion);
public static Version ICUVersion => m_icuVersion.Value;
Expand Down Expand Up @@ -357,7 +348,8 @@ private static Version GetICUVersion()
version & 0xFF);
}

private static readonly Lazy<bool> s_fileLockingDisabled = new Lazy<bool>(() => GetStaticNonPublicBooleanPropertyValue("Microsoft.Win32.SafeHandles.SafeFileHandle", "DisableFileLocking"));
private static readonly Lazy<bool> s_fileLockingDisabled = new Lazy<bool>(()
=> (bool?)Type.GetType("Microsoft.Win32.SafeHandles.SafeFileHandle")?.GetProperty("DisableFileLocking", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) == true);

public static bool IsFileLockingEnabled => IsWindows || !s_fileLockingDisabled.Value;

Expand Down

0 comments on commit 5982087

Please sign in to comment.