diff options
author | B Stack <bgstack15@gmail.com> | 2020-05-17 17:14:47 +0000 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-05-17 17:14:47 +0000 |
commit | cca3f71f16f85f5d506bf4bb7b3ec38fda31516a (patch) | |
tree | 1f52055b2f26fc2389d3ab4eb8d8d1e234a6316a /zen/system.cpp | |
parent | Merge branch '10.23' into 'master' (diff) | |
parent | add upstream 10.24 (diff) | |
download | FreeFileSync-cca3f71f16f85f5d506bf4bb7b3ec38fda31516a.tar.gz FreeFileSync-cca3f71f16f85f5d506bf4bb7b3ec38fda31516a.tar.bz2 FreeFileSync-cca3f71f16f85f5d506bf4bb7b3ec38fda31516a.zip |
Merge branch '10.24' into 'master'
add upstream 10.24
See merge request opensource-tracking/FreeFileSync!21
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()); } |