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

@ -95,7 +95,7 @@ platform_sources = {
'dragonfly' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'], 'dragonfly' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'],
'freebsd' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'], 'freebsd' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'],
'haiku' : ['src/os/haiku.cpp', 'src/os/haiku/package.cpp'], 'haiku' : ['src/os/haiku.cpp', 'src/os/haiku/package.cpp'],
'linux' : ['src/os/linux.cpp', 'src/os/linux/package.cpp'], 'linux' : ['src/os/linux.cpp'],
'netbsd' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'], 'netbsd' : ['src/os/bsd.cpp', 'src/os/bsd/package.cpp'],
'serenity' : ['src/os/serenity.cpp', 'src/os/serenity/package.cpp'], 'serenity' : ['src/os/serenity.cpp', 'src/os/serenity/package.cpp'],
'windows' : ['src/os/windows.cpp'], 'windows' : ['src/os/windows.cpp'],

View file

@ -1,23 +1,30 @@
#ifdef __linux__ #ifdef __linux__
// clang-format off // clang-format off
#include <cstring> // std::strlen #include <SQLiteCpp/Database.h> // SQLite::{Database, OPEN_READONLY}
#include <dbus/dbus-shared.h> // DBUS_BUS_SESSION #include <SQLiteCpp/Exception.h> // SQLite::Exception
#include <dbus/dbus-protocol.h> // DBUS_TYPE_* #include <SQLiteCpp/Statement.h> // SQLite::Statement
#include <expected> // std::{unexpected, expected} #include <climits> // PATH_MAX
#include <format> // std::{format, format_to_n} #include <cstring> // std::strlen
#include <fstream> // std::ifstream #include <dbus/dbus-protocol.h> // DBUS_TYPE_*
#include <climits> // PATH_MAX #include <dbus/dbus-shared.h> // DBUS_BUS_SESSION
#include <limits> // std::numeric_limits #include <expected> // std::{unexpected, expected}
#include <string> // std::{getline, string (String)} #include <filesystem> // std::filesystem::{current_path, directory_entry, directory_iterator, etc.}
#include <string_view> // std::string_view (StringView) #include <format> // std::{format, format_to_n}
#include <sys/socket.h> // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED #include <fstream> // std::ifstream
#include <sys/statvfs.h> // statvfs #include <glaze/beve/read.hpp> // glz::read_beve
#include <sys/sysinfo.h> // sysinfo #include <glaze/beve/write.hpp> // glz::write_beve
#include <sys/utsname.h> // utsname, uname #include <limits> // std::numeric_limits
#include <unistd.h> // readlink #include <string> // std::{getline, string (String)}
#include <utility> // std::move #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/defs.hpp"
#include "src/util/error.hpp" #include "src/util/error.hpp"
#include "src/util/helpers.hpp" #include "src/util/helpers.hpp"
@ -472,4 +479,32 @@ namespace os {
} }
} // 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__ #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__