this is a better strcuture i think

This commit is contained in:
Mars 2025-05-04 18:12:56 -04:00
parent b929bda29f
commit a9be33dd79
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
3 changed files with 52 additions and 61 deletions

View file

@ -1,23 +1,30 @@
#ifdef __linux__
// clang-format off
#include <cstring> // std::strlen
#include <dbus/dbus-shared.h> // DBUS_BUS_SESSION
#include <dbus/dbus-protocol.h> // DBUS_TYPE_*
#include <expected> // std::{unexpected, expected}
#include <format> // std::{format, format_to_n}
#include <fstream> // std::ifstream
#include <climits> // PATH_MAX
#include <limits> // std::numeric_limits
#include <string> // std::{getline, string (String)}
#include <string_view> // std::string_view (StringView)
#include <sys/socket.h> // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED
#include <sys/statvfs.h> // statvfs
#include <sys/sysinfo.h> // sysinfo
#include <sys/utsname.h> // utsname, uname
#include <unistd.h> // readlink
#include <utility> // std::move
#include <SQLiteCpp/Database.h> // SQLite::{Database, OPEN_READONLY}
#include <SQLiteCpp/Exception.h> // SQLite::Exception
#include <SQLiteCpp/Statement.h> // SQLite::Statement
#include <climits> // PATH_MAX
#include <cstring> // std::strlen
#include <dbus/dbus-protocol.h> // DBUS_TYPE_*
#include <dbus/dbus-shared.h> // DBUS_BUS_SESSION
#include <expected> // std::{unexpected, expected}
#include <filesystem> // std::filesystem::{current_path, directory_entry, directory_iterator, etc.}
#include <format> // std::{format, format_to_n}
#include <fstream> // std::ifstream
#include <glaze/beve/read.hpp> // glz::read_beve
#include <glaze/beve/write.hpp> // glz::write_beve
#include <limits> // std::numeric_limits
#include <string> // std::{getline, string (String)}
#include <string_view> // std::string_view (StringView)
#include <sys/socket.h> // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED
#include <sys/statvfs.h> // statvfs
#include <sys/sysinfo.h> // sysinfo
#include <sys/utsname.h> // utsname, uname
#include <unistd.h> // readlink
#include <utility> // std::move
#include "src/core/package.hpp"
#include "src/util/defs.hpp"
#include "src/util/error.hpp"
#include "src/util/helpers.hpp"
@ -472,4 +479,32 @@ namespace os {
}
} // namespace os
namespace package {
using namespace std::string_literals;
fn GetDpkgCount() -> Result<u64, DracError> {
return GetCountFromDirectory("Dpkg", fs::current_path().root_path() / "var" / "lib" / "dpkg" / "info", ".list"s);
}
fn GetMossCount() -> Result<u64, DracError> {
const PackageManagerInfo mossInfo = {
.id = "moss",
.dbPath = "/.moss/db/install",
.countQuery = "SELECT COUNT(*) FROM meta",
};
Result<u64, DracError> countResult = GetCountFromDb(mossInfo);
if (countResult)
if (*countResult > 0)
return *countResult - 1;
return countResult;
}
fn GetPacmanCount() -> Result<u64, DracError> {
return GetCountFromDirectory("Pacman", fs::current_path().root_path() / "var" / "lib" / "pacman" / "local", true);
}
} // namespace package
#endif // __linux__

View file

@ -1,44 +0,0 @@
#ifdef __linux__
// clang-format off
#include "src/core/package.hpp"
#include <SQLiteCpp/Database.h> // SQLite::{Database, OPEN_READONLY}
#include <SQLiteCpp/Exception.h> // SQLite::Exception
#include <SQLiteCpp/Statement.h> // SQLite::Statement
#include <filesystem> // std::filesystem::{current_path, directory_entry, directory_iterator, etc.}
#include <glaze/beve/read.hpp> // glz::read_beve
#include <glaze/beve/write.hpp> // glz::write_beve
#include "src/util/defs.hpp"
// clang-format on
using namespace std::string_literals;
namespace package {
fn GetDpkgCount() -> Result<u64, DracError> {
return GetCountFromDirectory("Dpkg", fs::current_path().root_path() / "var" / "lib" / "dpkg" / "info", ".list"s);
}
fn GetMossCount() -> Result<u64, DracError> {
const PackageManagerInfo mossInfo = {
.id = "moss",
.dbPath = "/.moss/db/install",
.countQuery = "SELECT COUNT(*) FROM meta",
};
Result<u64, DracError> countResult = GetCountFromDb(mossInfo);
if (countResult)
if (*countResult > 0)
return *countResult - 1;
return countResult;
}
fn GetPacmanCount() -> Result<u64, DracError> {
return GetCountFromDirectory("Pacman", fs::current_path().root_path() / "var" / "lib" / "pacman" / "local", true);
}
} // namespace package
#endif // __linux__