hopefully this works

This commit is contained in:
Mars 2025-05-04 17:53:31 -04:00
parent 30b435cbd2
commit a04a8ea901
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
2 changed files with 31 additions and 4 deletions

View file

@ -145,10 +145,6 @@ namespace os {
return DiskSpace { .used_bytes = used_bytes, .total_bytes = total_bytes }; return DiskSpace { .used_bytes = used_bytes, .total_bytes = total_bytes };
} }
fn GetPackageCount() -> Result<u64, DracError> {
return Err(DracError(DracErrorCode::NotSupported, "Package count is not supported on SerenityOS"));
}
} // namespace os } // namespace os
#endif // __serenity__ #endif // __serenity__

View file

@ -0,0 +1,31 @@
#ifdef __serenity__
// clang-format off
#include "src/core/package.hpp"
#include "src/util/defs.hpp"
// clang-format on
namespace {
fn CountUniquePackages(const String& dbPath) -> Result<u64, DracError> {
std::ifstream dbFile(dbPath);
if (!dbFile.is_open())
return Err(DracError(DracErrorCode::NotFound, std::format("Failed to open file: {}", dbPath.string())));
std::unordered_set<String> uniquePackages;
String line;
while (std::getline(dbFile, line))
if (line.starts_with("manual ") || line.starts_with("auto "))
uniquePackages.insert(line);
return uniquePackages.size();
}
} // namespace
namespace package {
fn GetSerenityCount() -> Result<u64, DracError> { return CountUniquePackages("/usr/ports/installed.db"); }
} // namespace package
#endif // __serenity__