Skip to content

Commit d8be614

Browse files
gathdduCarterLicodacy-production[bot]
authored
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 <CarterLi@users.noreply.github.com> Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
1 parent 61968ca commit d8be614

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/detection/packages/packages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct FFPackagesResult {
2222
uint32_t guixUser;
2323
uint32_t hpkgSystem;
2424
uint32_t hpkgUser;
25+
uint32_t installrelease;
2526
uint32_t kiss;
2627
uint32_t linglong;
2728
uint32_t lpkg;

src/detection/packages/packages_linux.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,19 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
676676
result->appimage += getNumElementsBySuffix(&baseDir, "/AppImages", ".appimage");
677677
result->appimage += getNumElementsBySuffix(&baseDir, "/Applications", ".appimage");
678678
}
679+
680+
if (!(options->disabled & FF_PACKAGES_FLAG_INSTALLRELEASE_BIT)) {
681+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&baseDir);
682+
ffStrbufAppendS(&path, ".config/install_release/state.json");
683+
if (ffPathExists(path.chars, FF_PATHTYPE_FILE)) {
684+
yyjson_doc* doc = yyjson_read_file(path.chars, YYJSON_READ_NOFLAG, NULL, NULL);
685+
if (doc != NULL) {
686+
yyjson_val* root = yyjson_doc_get_root(doc);
687+
if (yyjson_is_obj(root)) {
688+
result->installrelease = (uint32_t) yyjson_obj_size(root);
689+
}
690+
yyjson_doc_free(doc);
691+
}
692+
}
693+
}
679694
}

src/modules/packages/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum FF_A_PACKED FFPackagesFlags {
4040
FF_PACKAGES_FLAG_APPIMAGE_BIT = UINT64_C(1) << 33U,
4141
FF_PACKAGES_FLAG_CARDS_BIT = UINT64_C(1) << 34U,
4242
FF_PACKAGES_FLAG_PORG_BIT = UINT64_C(1) << 35U,
43+
FF_PACKAGES_FLAG_INSTALLRELEASE_BIT = UINT64_C(1) << 36U,
4344
FF_PACKAGES_FLAG_FORCE_UNSIGNED = UINT64_MAX,
4445
} FFPackagesFlags;
4546
static_assert(sizeof(FFPackagesFlags) == sizeof(uint64_t), "");

src/modules/packages/packages.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ bool ffPrintPackages(FFPackagesOptions* options) {
8989
} else {
9090
FF_PRINT_PACKAGE_NAME(hpkgSystem, "hpkg")
9191
}
92+
FF_PRINT_PACKAGE_NAME(installrelease, "install-release")
9293
FF_PRINT_PACKAGE(kiss)
9394
FF_PRINT_PACKAGE(linglong)
9495
FF_PRINT_PACKAGE(lpkg)
@@ -163,6 +164,7 @@ bool ffPrintPackages(FFPackagesOptions* options) {
163164
FF_ARG(counts.guixUser, "guix-user"),
164165
FF_ARG(counts.hpkgSystem, "hpkg-system"),
165166
FF_ARG(counts.hpkgUser, "hpkg-user"),
167+
FF_ARG(counts.installrelease, "install-release"),
166168
FF_ARG(counts.kiss, "kiss"),
167169
FF_ARG(counts.linglong, "linglong"),
168170
FF_ARG(counts.lpkg, "lpkg"),
@@ -282,6 +284,11 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) {
282284
;
283285
FF_TEST_PACKAGE_NAME(HPKG)
284286
break;
287+
case 'I':
288+
if (false)
289+
;
290+
FF_TEST_PACKAGE_NAME(INSTALLRELEASE)
291+
break;
285292
case 'K':
286293
if (false)
287294
;
@@ -454,6 +461,7 @@ bool ffGeneratePackagesJsonResult(FFPackagesOptions* options, yyjson_mut_doc* do
454461
FF_APPEND_PACKAGE_COUNT(guixUser)
455462
FF_APPEND_PACKAGE_COUNT(hpkgSystem)
456463
FF_APPEND_PACKAGE_COUNT(hpkgUser)
464+
FF_APPEND_PACKAGE_COUNT(installrelease)
457465
FF_APPEND_PACKAGE_COUNT(kiss)
458466
FF_APPEND_PACKAGE_COUNT(linglong)
459467
FF_APPEND_PACKAGE_COUNT(lpkg)
@@ -529,6 +537,7 @@ FFModuleBaseInfo ffPackagesModuleInfo = {
529537
{ "Number of guix-user packages", "guix-user" },
530538
{ "Number of hpkg-system packages", "hpkg-system" },
531539
{ "Number of hpkg-user packages", "hpkg-user" },
540+
{ "Number of install-release packages", "install-release" },
532541
{ "Number of kiss packages", "kiss" },
533542
{ "Number of linglong packages", "linglong" },
534543
{ "Number of lpkg packages", "lpkg" },

0 commit comments

Comments
 (0)