]> git.pld-linux.org Git - packages/wxWidgets.git/blob - os-release.patch
- up to 3.2.2.1
[packages/wxWidgets.git] / os-release.patch
1 From 1b0c5d63f6269afa46d121c28160a339da5dd5b7 Mon Sep 17 00:00:00 2001
2 From: Scott Talbert <swt@techie.net>
3 Date: Fri, 14 Jul 2023 11:45:19 -0400
4 Subject: [PATCH] Read Linux distribution info from os-release file
5
6 The Linux distribution community has somewhat deprecated the lsb_release
7 utility and has standardized on a new file, os-release, that can be
8 simply parsed to get the same information.  Attempt to read this file in
9 /etc/os-release, then /usr/lib/os-release, and finally, fall back to
10 using the lsb_release utility if neither of those files are found.
11
12 See: https://www.freedesktop.org/software/systemd/man/os-release.html
13 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2184391
14
15 See #23712.
16
17 (cherry picked from commit aef7df6c9f44f751d97f4f6519ae6e5c3b81019d)
18 ---
19  docs/changes.txt      |  1 +
20  src/unix/utilsunx.cpp | 30 ++++++++++++++++++++++++++++++
21  2 files changed, 31 insertions(+)
22
23 diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
24 index ac5181e187f3..302aaa25b8f5 100644
25 --- a/src/unix/utilsunx.cpp
26 +++ b/src/unix/utilsunx.cpp
27 @@ -62,6 +62,8 @@
28  #include "wx/evtloop.h"
29  #include "wx/mstream.h"
30  #include "wx/private/fdioeventloopsourcehandler.h"
31 +#include "wx/config.h"
32 +#include "wx/filename.h"
33  
34  #include <pwd.h>
35  #include <sys/wait.h>       // waitpid()
36 @@ -1147,6 +1149,23 @@ wxString wxGetNativeCpuArchitectureName()
37  
38  #ifdef __LINUX__
39  
40 +static bool
41 +wxGetValuesFromOSRelease(const wxString& filename, wxLinuxDistributionInfo& ret)
42 +{
43 +    if ( !wxFileName::Exists(filename) )
44 +    {
45 +        return false;
46 +    }
47 +
48 +    wxFileConfig fc(wxEmptyString, wxEmptyString, wxEmptyString, filename);
49 +    ret.Id = fc.Read(wxS("ID"), wxEmptyString).Capitalize();
50 +    ret.Description = fc.Read(wxS("PRETTY_NAME"), wxEmptyString);
51 +    ret.Release = fc.Read(wxS("VERSION_ID"), wxEmptyString);
52 +    ret.CodeName = fc.Read(wxS("VERSION_CODENAME"), wxEmptyString);
53 +
54 +    return true;
55 +}
56 +
57  static bool
58  wxGetValueFromLSBRelease(const wxString& arg, const wxString& lhs, wxString* rhs)
59  {
60 @@ -1161,6 +1180,17 @@ wxLinuxDistributionInfo wxGetLinuxDistributionInfo()
61  {
62      wxLinuxDistributionInfo ret;
63  
64 +    // Read /etc/os-release and fall back to /usr/lib/os-release per below
65 +    // https://www.freedesktop.org/software/systemd/man/os-release.html
66 +    if ( wxGetValuesFromOSRelease(wxS("/etc/os-release"), ret) )
67 +    {
68 +        return ret;
69 +    }
70 +    if ( wxGetValuesFromOSRelease(wxS("/usr/lib/os-release"), ret) )
71 +    {
72 +        return ret;
73 +    }
74 +
75      if ( !wxGetValueFromLSBRelease(wxS("--id"), wxS("Distributor ID:\t"),
76                                     &ret.Id) )
77      {
This page took 0.062058 seconds and 3 git commands to generate.