diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-04-17 15:05:20 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-04-17 15:05:20 +0200 |
| commit | 79bdca04e2cc9e13bbfa1cac7619d5e4a56ff0bd (patch) | |
| tree | 1d267c727247c1b20dc113737ce356f3b7fa09a0 /src/package.cpp | |
| parent | 34b10f41aa285e423cccb161342b68ae7275da4b (diff) | |
| download | slackbuilder-79bdca04e2cc9e13bbfa1cac7619d5e4a56ff0bd.tar.gz | |
Remove SBo differ experiment
Diffstat (limited to 'src/package.cpp')
| -rw-r--r-- | src/package.cpp | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/src/package.cpp b/src/package.cpp deleted file mode 100644 index 9fc99e4..0000000 --- a/src/package.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "package.h" -#include <filesystem> - -namespace katja -{ - package::package(const std::string& name, const std::string& version, - const std::string& architecture, const std::string& tag) - : m_name(name), m_version(version), m_architecture(architecture), m_tag(tag) - { - } - - const std::string& package::name() const noexcept - { - return m_name; - } - - const std::string& package::version() const noexcept - { - return m_version; - } - - const std::string& package::architecture() const noexcept - { - return m_architecture; - } - - const std::string& package::tag() const noexcept - { - return m_tag; - } - - std::optional<package> package::parse(const std::string& full_name) noexcept - { - std::size_t tag_separator = full_name.find_last_of('-'); - - if (tag_separator == std::string::npos || tag_separator == 0) - { - return std::nullopt; - } - std::size_t architecture_separator = full_name.find_last_of('-', tag_separator - 1); - - if (architecture_separator == std::string::npos || architecture_separator == 0) - { - return std::nullopt; - } - std::size_t version_separator = full_name.find_last_of('-', architecture_separator - 1); - - if (version_separator == std::string::npos || version_separator == 0) - { - return std::nullopt; - } - package parsed_package{ - full_name.substr(0, version_separator), - full_name.substr(version_separator + 1, architecture_separator - version_separator - 1), - full_name.substr(architecture_separator + 1, tag_separator - architecture_separator - 1), - full_name.substr(tag_separator + 1) - }; - return std::make_optional(parsed_package); - } - - std::unordered_map<std::string, package> read_package_database() - { - std::unordered_map<std::string, package> packages; - - for (const auto& entry : std::filesystem::directory_iterator("/var/lib/pkgtools/packages")) - { - std::optional<package> maybe_package = package::parse(entry.path().filename()); - - if (maybe_package.has_value()) - { - packages.insert_or_assign(maybe_package.value().name(), maybe_package.value()); - } - } - return packages; - } - - package_exception::package_exception(const std::string& package_name, const std::string& reason) noexcept - : m_message(package_name) - { - m_message.reserve(m_message.size() + 2 + reason.size()); - m_message += ": " + reason; - } - - const std::string_view package_exception::package_name() const noexcept - { - std::size_t colon_position = m_message.find(':'); - - if (colon_position == std::string::npos) - { - return std::string_view(m_message); - } - else if (colon_position == 0) - { - return std::string_view(""); - } - else - { - return std::string_view(m_message.c_str(), colon_position - 1); - } - } - - const char *package_exception::what() const noexcept - { - return m_message.c_str(); - } -} |
