From d8be61411ee0952d59a046cd32cf655074081fb0 Mon Sep 17 00:00:00 2001 From: Jess Date: Mon, 22 Jun 2026 02:23:21 -0300 Subject: [PATCH] Packages (Linux): add install-release package count support (#2342) * feat: add install-release package count support * Apply suggestion from @codacy-production[bot] Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com> * Fix formatting of ffParsePropFileValues call --------- Co-authored-by: Carter Li Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com> --- src/detection/packages/packages.h | 1 + src/detection/packages/packages_linux.c | 15 +++++++++++++++ src/modules/packages/option.h | 1 + src/modules/packages/packages.c | 9 +++++++++ 4 files changed, 26 insertions(+) diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index a29e7dba9..211934932 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -22,6 +22,7 @@ typedef struct FFPackagesResult { uint32_t guixUser; uint32_t hpkgSystem; uint32_t hpkgUser; + uint32_t installrelease; uint32_t kiss; uint32_t linglong; uint32_t lpkg; diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 18c796bb3..35ee02143 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -676,4 +676,19 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) result->appimage += getNumElementsBySuffix(&baseDir, "/AppImages", ".appimage"); result->appimage += getNumElementsBySuffix(&baseDir, "/Applications", ".appimage"); } + + if (!(options->disabled & FF_PACKAGES_FLAG_INSTALLRELEASE_BIT)) { + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&baseDir); + ffStrbufAppendS(&path, ".config/install_release/state.json"); + if (ffPathExists(path.chars, FF_PATHTYPE_FILE)) { + yyjson_doc* doc = yyjson_read_file(path.chars, YYJSON_READ_NOFLAG, NULL, NULL); + if (doc != NULL) { + yyjson_val* root = yyjson_doc_get_root(doc); + if (yyjson_is_obj(root)) { + result->installrelease = (uint32_t) yyjson_obj_size(root); + } + yyjson_doc_free(doc); + } + } + } } diff --git a/src/modules/packages/option.h b/src/modules/packages/option.h index 75884f33c..c215593c2 100644 --- a/src/modules/packages/option.h +++ b/src/modules/packages/option.h @@ -40,6 +40,7 @@ typedef enum FF_A_PACKED FFPackagesFlags { FF_PACKAGES_FLAG_APPIMAGE_BIT = UINT64_C(1) << 33U, FF_PACKAGES_FLAG_CARDS_BIT = UINT64_C(1) << 34U, FF_PACKAGES_FLAG_PORG_BIT = UINT64_C(1) << 35U, + FF_PACKAGES_FLAG_INSTALLRELEASE_BIT = UINT64_C(1) << 36U, FF_PACKAGES_FLAG_FORCE_UNSIGNED = UINT64_MAX, } FFPackagesFlags; static_assert(sizeof(FFPackagesFlags) == sizeof(uint64_t), ""); diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index ee8ecb8bf..8cb4027bd 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -89,6 +89,7 @@ bool ffPrintPackages(FFPackagesOptions* options) { } else { FF_PRINT_PACKAGE_NAME(hpkgSystem, "hpkg") } + FF_PRINT_PACKAGE_NAME(installrelease, "install-release") FF_PRINT_PACKAGE(kiss) FF_PRINT_PACKAGE(linglong) FF_PRINT_PACKAGE(lpkg) @@ -163,6 +164,7 @@ bool ffPrintPackages(FFPackagesOptions* options) { FF_ARG(counts.guixUser, "guix-user"), FF_ARG(counts.hpkgSystem, "hpkg-system"), FF_ARG(counts.hpkgUser, "hpkg-user"), + FF_ARG(counts.installrelease, "install-release"), FF_ARG(counts.kiss, "kiss"), FF_ARG(counts.linglong, "linglong"), FF_ARG(counts.lpkg, "lpkg"), @@ -282,6 +284,11 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) { ; FF_TEST_PACKAGE_NAME(HPKG) break; + case 'I': + if (false) + ; + FF_TEST_PACKAGE_NAME(INSTALLRELEASE) + break; case 'K': if (false) ; @@ -454,6 +461,7 @@ bool ffGeneratePackagesJsonResult(FFPackagesOptions* options, yyjson_mut_doc* do FF_APPEND_PACKAGE_COUNT(guixUser) FF_APPEND_PACKAGE_COUNT(hpkgSystem) FF_APPEND_PACKAGE_COUNT(hpkgUser) + FF_APPEND_PACKAGE_COUNT(installrelease) FF_APPEND_PACKAGE_COUNT(kiss) FF_APPEND_PACKAGE_COUNT(linglong) FF_APPEND_PACKAGE_COUNT(lpkg) @@ -529,6 +537,7 @@ FFModuleBaseInfo ffPackagesModuleInfo = { { "Number of guix-user packages", "guix-user" }, { "Number of hpkg-system packages", "hpkg-system" }, { "Number of hpkg-user packages", "hpkg-user" }, + { "Number of install-release packages", "install-release" }, { "Number of kiss packages", "kiss" }, { "Number of linglong packages", "linglong" }, { "Number of lpkg packages", "lpkg" },