Skip to content

Commit ba31311

Browse files
committed
Address @bermeister's feedback
1 parent bb2cf28 commit ba31311

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/CompatibilityProfileCollector.cs

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public CompatibilityProfileCollector Build(SMA.PowerShell pwsh)
8282
}
8383
}
8484

85+
// Increment the minor version if non-breaking additions have been made to the API
86+
// Increment the major version if breaking changes have been made to the API
8587
private static readonly Version s_currentProfileSchemaVersion = new Version(1, 2);
8688

8789
private readonly PowerShellDataCollector _pwshDataCollector;

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs

+39-30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ namespace Microsoft.PowerShell.CrossCompatibility.Collection
2323
/// </summary>
2424
public class PlatformInformationCollector : IDisposable
2525
{
26+
// Paths on Linux to search for key/value-paired information about the OS.
27+
private static readonly IReadOnlyCollection<string> s_releaseInfoPaths = new string[]
28+
{
29+
"/etc/lsb-release",
30+
"/etc/os-release",
31+
};
32+
33+
private static readonly IReadOnlyList<string> s_distributionIdKeys = new string[]
34+
{
35+
"ID",
36+
"DISTRIB_ID"
37+
};
38+
39+
private static readonly IReadOnlyList<string> s_distributionVersionKeys = new string[]
40+
{
41+
"VERSION_ID",
42+
"DISTRIB_RELEASE"
43+
};
44+
45+
private static readonly IReadOnlyList<string> s_distributionPrettyNameKeys = new string[]
46+
{
47+
"PRETTY_NAME",
48+
"DISTRIB_DESCRIPTION"
49+
};
50+
51+
private static readonly Regex s_macOSNameRegex = new Regex(
52+
@"System Version: (.*?)(\(|$)",
53+
RegexOptions.Multiline | RegexOptions.Compiled);
54+
55+
2656
/// <summary>
2757
/// Collect all release info files into a lookup table in memory.
2858
/// Overrides pre-existing keys if there are duplicates.
@@ -55,42 +85,21 @@ public static IReadOnlyDictionary<string, string> GetLinuxReleaseInfo()
5585
}
5686
catch (IOException)
5787
{
58-
// Do nothing - just continue
88+
// Different Linux distributions have different /etc/*-release files.
89+
// It's more efficient (and correct timing-wise) for us to try to read the file and catch the exception
90+
// than to test for its existence and then open it.
91+
//
92+
// See:
93+
// - https://www.freedesktop.org/software/systemd/man/os-release.html
94+
// - https://gist.github.com/natefoo/814c5bf936922dad97ff
95+
96+
// Ignore that the file doesn't exist and just continue to the next one.
5997
}
6098
}
6199

62100
return dict;
63101
}
64102

65-
// Paths on Linux to search for key/value-paired information about the OS.
66-
private static readonly IReadOnlyCollection<string> s_releaseInfoPaths = new string[]
67-
{
68-
"/etc/lsb-release",
69-
"/etc/os-release",
70-
};
71-
72-
private static readonly IReadOnlyList<string> s_distributionIdKeys = new string[]
73-
{
74-
"ID",
75-
"DISTRIB_ID"
76-
};
77-
78-
private static readonly IReadOnlyList<string> s_distributionVersionKeys = new string[]
79-
{
80-
"VERSION_ID",
81-
"DISTRIB_RELEASE"
82-
};
83-
84-
private static readonly IReadOnlyList<string> s_distributionPrettyNameKeys = new string[]
85-
{
86-
"PRETTY_NAME",
87-
"DISTRIB_DESCRIPTION"
88-
};
89-
90-
private static readonly Regex s_macOSNameRegex = new Regex(
91-
@"System Version: (.*?)(\(|$)",
92-
RegexOptions.Multiline | RegexOptions.Compiled);
93-
94103
private readonly Lazy<Hashtable> _lazyPSVersionTable;
95104

96105
private readonly Lazy<PowerShellVersion> _lazyPSVersion;

0 commit comments

Comments
 (0)