From 451bc394eeffe2e1b709cf4fd102de8400db528d Mon Sep 17 00:00:00 2001 From: Oliver Lin Date: Wed, 6 May 2026 09:43:17 +0800 Subject: [PATCH] OS (Linux): enhances Deepin version detection using /etc/os-version (#2300) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(os): enhance Deepin detection with os-version data Add a Deepin-specific enhancement in Linux OS detection that reads `/etc/os-version` for `MinorVersion` and `EditionName`. When available, it now: - sets `versionID` to `MinorVersion` - updates `prettyName` to include version and optional edition This improves Deepin version accuracy and provides a clearer OS name than relying solely on generic `os-release` fields.feat(os): enhance Deepin detection with os-version data Add a Deepin-specific enhancement in Linux OS detection that reads `/etc/os-version` for `MinorVersion` and `EditionName`. When available, it now: - sets `versionID` to `MinorVersion` - updates `prettyName` to include version and optional edition This improves Deepin version accuracy and provides a clearer OS name than relying solely on generic `os-release` fields. * fix(os): use distro name when formatting Deepin prettyName Update Deepin enhancement formatting to build `prettyName` from `result->name` instead of hardcoding "Deepin". This keeps output consistent with the detected distro name while still appending version and edition details.fix(os): use distro name when formatting Deepin prettyName Update Deepin enhancement formatting to build `prettyName` from `result->name` instead of hardcoding "Deepin". This keeps output consistent with the detected distro name while still appending version and edition details. * fix(os/linux): guard Deepin minor version override Only apply Deepin’s `minor` value to `versionID` when an edition is present and `prettyName` does not already include parenthesized details. This avoids incorrectly overriding parsed version info in enhanced names.fix(os/linux): guard Deepin minor version override Only apply Deepin’s `minor` value to `versionID` when an edition is present and `prettyName` does not already include parenthesized details. This avoids incorrectly overriding parsed version info in enhanced names. Co-authored-by: Copilot * Refactor Deepin enhancement detection logic * Refactor detectDeepinEnhancement function --------- Co-authored-by: Copilot Co-authored-by: Carter Li --- src/detection/os/os_linux.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 2c6fd4785..b07bc3a2e 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -95,8 +95,7 @@ FF_A_UNUSED static bool getUbuntuFlavour(FFOSResult* result) { } // xdgConfigDirs contains plasma only - if (ffPathExists("/var/lib/dpkg/info/ubuntustudio-desktop.list", FF_PATHTYPE_FILE)) - { + if (ffPathExists("/var/lib/dpkg/info/ubuntustudio-desktop.list", FF_PATHTYPE_FILE)) { ffStrbufSetStatic(&result->name, "Ubuntu Studio"); ffStrbufSetStatic(&result->id, "ubuntu-studio"); ffStrbufSetStatic(&result->idLike, "ubuntu"); @@ -306,6 +305,34 @@ static bool detectBedrock(FFOSResult* os) { return parseOsRelease(FASTFETCH_TARGET_DIR_ROOT "/bedrock/strata/bedrock/etc/os-release", os); } +static void detectDeepinEnhancement(FFOSResult* result) { + if (ffStrbufContainC(&result->prettyName, '(')) { + return; + } + + FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate(); + FF_STRBUF_AUTO_DESTROY edition = ffStrbufCreate(); + + if (!ffParsePropFileValues( + FASTFETCH_TARGET_DIR_ETC "/os-version", + 2, + (FFpropquery[]) { + { "MinorVersion=", &minor }, + { "EditionName=", &edition }, + }) || + minor.length == 0) { + return; + } + + ffStrbufSet(&result->versionID, &minor); + + if (edition.length > 0) { + ffStrbufSetF(&result->prettyName, "%s %s (%s)", result->name.chars, minor.chars, edition.chars); + } else { + ffStrbufSetF(&result->prettyName, "%s %s", result->name.chars, minor.chars); + } +} + static void detectOS(FFOSResult* os) { #ifdef FF_CUSTOM_OS_RELEASE_PATH parseOsRelease(FF_STR(FF_CUSTOM_OS_RELEASE_PATH), os); @@ -322,6 +349,7 @@ static void detectOS(FFOSResult* os) { // Refer: https://gist.github.com/natefoo/814c5bf936922dad97ff parseOsRelease(FASTFETCH_TARGET_DIR_ETC "/os-release", os); + if (os->id.length == 0 || os->version.length == 0 || os->prettyName.length == 0 || os->codename.length == 0) { parseLsbRelease(FASTFETCH_TARGET_DIR_ETC "/lsb-release", os); } @@ -360,6 +388,8 @@ void ffDetectOSImpl(FFOSResult* os) { ffStrbufSetS(&os->id, "lmde"); ffStrbufSetS(&os->idLike, "linuxmint"); } + } else if (ffStrbufEqualS(&os->id, "deepin")) { + detectDeepinEnhancement(os); } #endif }