hopefully this works
This commit is contained in:
parent
30b435cbd2
commit
a04a8ea901
2 changed files with 31 additions and 4 deletions
|
@ -145,10 +145,6 @@ namespace os {
|
|||
|
||||
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
|
||||
|
||||
#endif // __serenity__
|
||||
|
|
31
src/os/serenity/package.cpp
Normal file
31
src/os/serenity/package.cpp
Normal 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__
|
Loading…
Add table
Add a link
Reference in a new issue