Skip to content

Commit 2fe7476

Browse files
Better xbps package count
#209
1 parent 03cbd64 commit 2fe7476

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/modules/packages.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,30 @@ static uint32_t getRpmFromLibrpm(const FFinstance* instance)
195195
}
196196
#endif
197197

198+
static uint32_t getXBPS(FFstrbuf* baseDir)
199+
{
200+
DIR* dir = opendir(baseDir->chars);
201+
if(dir == NULL)
202+
return 0;
203+
204+
uint32_t result = 0;
205+
206+
struct dirent *entry;
207+
while((entry = readdir(dir)) != NULL)
208+
{
209+
if(entry->d_type != DT_REG || strncasecmp(entry->d_name, "pkgdb-", 6) != 0)
210+
continue;
211+
212+
ffStrbufAppendC(baseDir, '/');
213+
ffStrbufAppendS(baseDir, entry->d_name);
214+
result = getNumStrings(baseDir->chars, "<string>installed</string>");
215+
break;
216+
}
217+
218+
closedir(dir);
219+
return result;
220+
}
221+
198222
static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, PackageCounts* packageCounts)
199223
{
200224
uint32_t baseDirLength = baseDir->length;
@@ -221,7 +245,7 @@ static void getPackageCounts(const FFinstance* instance, FFstrbuf* baseDir, Pack
221245

222246
//xps
223247
ffStrbufAppendS(baseDir, "/var/db/xbps");
224-
packageCounts->xbps += getNumElements(baseDir->chars, DT_REG);
248+
packageCounts->xbps += getXBPS(baseDir);
225249
ffStrbufSubstrBefore(baseDir, baseDirLength);
226250

227251
//flatpak

0 commit comments

Comments
 (0)