feat(linux-packages): add dpkg packages count

This commit is contained in:
utox39 committed 2025-12-09 18:25:57 +01:00
1 parent e2cbda50c1
commit a64db7a7d3
1 file changed
+20
+20
View File
@@ -30,3 +30,23 @@ fn countNixPackages(allocator: std.mem.Allocator) !usize {
return try std.fmt.parseInt(usize, result_trimmed, 10); return try std.fmt.parseInt(usize, result_trimmed, 10);
} }
fn countDpkgPackages(allocator: std.mem.Allocator) !usize {
const dpkg_status_path = "/var/lib/dpkg/status";
const dpkg_file = try std.fs.cwd().openFile(dpkg_status_path, .{ .mode = .read_only });
defer dpkg_file.close();
const file_size = (try dpkg_file.stat()).size;
const content = try utils.readFile(allocator, dpkg_file, file_size);
defer allocator.free(content);
var count: usize = 0;
var iter = std.mem.splitSequence(u8, content, "\n\n");
// TODO: find a way to avoid this loop
while (iter.next()) |_| {
count += 1;
}
// Subtruct 1 to remove an empty line
return count - 1;
}