From 2a927b38c061b6b3f5220dac9d32fb999a017a93 Mon Sep 17 00:00:00 2001 From: Oscar Cowdery Lack Date: Sun, 10 Apr 2022 10:35:39 +1000 Subject: [PATCH] Fall back to /usr/lib/os-release if /etc/os-release doesn't exist From https://www.freedesktop.org/software/systemd/man/os-release.html: > The file /etc/os-release takes precedence over /usr/lib/os-release. > Applications should check for the former, and exclusively use its data > if it exists, and only fall back to /usr/lib/os-release if it is > missing. --- scripts/platform.cake | 16 ++++++++++++++-- src/OmniSharp.Shared/Utilities/Platform.cs | 7 ++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/platform.cake b/scripts/platform.cake index 2338675b81..31e1ef8d8e 100644 --- a/scripts/platform.cake +++ b/scripts/platform.cake @@ -105,11 +105,23 @@ public sealed class Platform private static void ReadDistroNameAndVersion(out string distroName, out Version version) { - var lines = System.IO.File.ReadAllLines("/etc/os-release"); - distroName = null; version = null; + string OS_Release_Path = "/etc/os-release"; + + if (!System.IO.File.Exists(OS_Release_Path)) + { + OS_Release_Path = "/usr/lib/os-release"; + } + + if (!System.IO.File.Exists(OS_Release_Path)) + { + return; + } + + var lines = System.IO.File.ReadAllLines(OS_Release_Path); + foreach (var line in lines) { var equalsIndex = line.IndexOf('='); diff --git a/src/OmniSharp.Shared/Utilities/Platform.cs b/src/OmniSharp.Shared/Utilities/Platform.cs index 2b9eda18f7..1a483e57e9 100644 --- a/src/OmniSharp.Shared/Utilities/Platform.cs +++ b/src/OmniSharp.Shared/Utilities/Platform.cs @@ -136,7 +136,12 @@ private static void ReadDistroNameAndVersion(out string distroName, out Version version = null; // Details: https://www.freedesktop.org/software/systemd/man/os-release.html - const string OS_Release_Path = "/etc/os-release"; + string OS_Release_Path = "/etc/os-release"; + + if (!File.Exists(OS_Release_Path)) + { + OS_Release_Path = "/usr/lib/os-release"; + } if (!File.Exists(OS_Release_Path)) {