diff options
author | B Stack <bgstack15@gmail.com> | 2020-05-17 11:17:28 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-05-17 11:17:28 -0400 |
commit | f0f3f094c5fa05bafe1963d1ea13f1be39a6673b (patch) | |
tree | 1f52055b2f26fc2389d3ab4eb8d8d1e234a6316a /zen/system.cpp | |
parent | Merge branch '10.23' into 'master' (diff) | |
download | FreeFileSync-f0f3f094c5fa05bafe1963d1ea13f1be39a6673b.tar.gz FreeFileSync-f0f3f094c5fa05bafe1963d1ea13f1be39a6673b.tar.bz2 FreeFileSync-f0f3f094c5fa05bafe1963d1ea13f1be39a6673b.zip |
add upstream 10.24
Diffstat (limited to 'zen/system.cpp')
-rw-r--r-- | zen/system.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/zen/system.cpp b/zen/system.cpp index d9a169c7..aa967f71 100644 --- a/zen/system.cpp +++ b/zen/system.cpp @@ -96,22 +96,31 @@ std::wstring zen::getOsDescription() //throw FileError { try { - std::wstring osName; - std::wstring osVersion; - - if (const auto [exitCode, output] = consoleExecute("lsb_release --id -s", std::nullopt); //throw SysError - exitCode != 0) - throw SysError(formatSystemError("lsb_release --id", replaceCpy(_("Exit code %x"), L"%x", numberTo<std::wstring>(exitCode)), output)); - else - osName = trimCpy(output); - - if (const auto [exitCode, output] = consoleExecute("lsb_release --release -s", std::nullopt); //throw SysError - exitCode != 0) - throw SysError(formatSystemError("lsb_release --release", replaceCpy(_("Exit code %x"), L"%x", numberTo<std::wstring>(exitCode)), output)); - else - osVersion = trimCpy(output); - - return osName + L' ' + osVersion; //e.g. "CentOS 7.7.1908" + //"lsb_release" not available on some systems: https://freefilesync.org/forum/viewtopic.php?t=7191 + // => use /etc/os-release: https://www.freedesktop.org/software/systemd/man/os-release.html + std::string releaseInfo; + try + { + releaseInfo = loadBinContainer<std::string>("/etc/os-release", nullptr /*notifyUnbufferedIO*/); //throw FileError + } + catch (const FileError& e) { throw SysError(e.toString()); } //further enrich with context info => SysError + + std::string osName; + std::string osVersion; + for (const std::string& line : split(releaseInfo, '\n', SplitType::SKIP_EMPTY)) //throw FileError + if (startsWith(line, "NAME=")) + osName = afterFirst(line, '=', IF_MISSING_RETURN_NONE); + else if (startsWith(line, "VERSION_ID=")) + osVersion = afterFirst(line, '=', IF_MISSING_RETURN_NONE); + + trim(osName, true, true, [](char c) { return c == '"' || c == '\''; }); + trim(osVersion, true, true, [](char c) { return c == '"' || c == '\''; }); + + if (osName .empty()) throw SysError(formatSystemError("/etc/os-release", L"", L"NAME missing.")); + if (osVersion.empty()) throw SysError(formatSystemError("/etc/os-release", L"", L"VERSION_ID missing.")); + + //PRETTY_NAME? too wordy! e.g. "Fedora 17 (Beefy Miracle)" + return utfTo<std::wstring>(osName + ' ' + osVersion); //e.g. "CentOS Linux 7" } catch (const SysError& e) { throw FileError(_("Cannot get process information."), e.toString()); } |