aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/main.cpp16
-rw-r--r--include/katja/database.hpp10
-rw-r--r--include/katja/repository.hpp20
-rw-r--r--include/katja/sbo.hpp14
-rw-r--r--katja/repository.cpp19
-rw-r--r--katja/sbo.cpp53
6 files changed, 111 insertions, 21 deletions
diff --git a/cli/main.cpp b/cli/main.cpp
index c417b83..c257dbd 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -6,25 +6,19 @@
int main(int argc, const char **argv)
{
- std::vector<katja::info_file> info_files;
std::multimap<std::string, katja::database_package> installed_database = katja::read_installed_database();
if (argc > 1)
{
std::filesystem::path slackbuild_repository{ argv[1] };
+ katja::sbo_repository repository{ slackbuild_repository };
+ auto updates = repository.get_updates(installed_database);
- katja::search_for_slackbuilds(info_files, slackbuild_repository);
- for (const auto& slackbuild_info : info_files)
+ for (const auto& package_identifier : updates)
{
- std::multimap<std::string, katja::database_package>::const_iterator installed_package =
- installed_database.find(slackbuild_info.program_name);
-
- if (installed_package != installed_database.cend())
- {
- std::cout << slackbuild_info.program_name << " " << slackbuild_info.version
- << " (installed " << installed_package->second.version << ")" << std::endl;
- }
+ std::cout << package_identifier.to_string() << std::endl;
}
+ std::cout << "SlackBuilds found: " << updates.size() << std::endl;
}
return 0;
}
diff --git a/include/katja/database.hpp b/include/katja/database.hpp
index ee4816e..ca85ab1 100644
--- a/include/katja/database.hpp
+++ b/include/katja/database.hpp
@@ -20,10 +20,10 @@ namespace katja
static database_package create_database_package(const std::string& fullname);
public:
- const std::string build_tag;
- const std::string architecture;
- const std::string version;
const std::string name;
+ const std::string version;
+ const std::string architecture;
+ const std::string build_tag;
database_package(const std::string& fullname);
@@ -33,5 +33,7 @@ namespace katja
std::string to_string() const;
};
- std::multimap<std::string, database_package> read_installed_database();
+ using package_database = std::multimap<std::string, database_package>;
+
+ package_database read_installed_database();
}
diff --git a/include/katja/repository.hpp b/include/katja/repository.hpp
index ca20277..0a799bd 100644
--- a/include/katja/repository.hpp
+++ b/include/katja/repository.hpp
@@ -5,6 +5,26 @@
*/
#pragma once
+#include <string>
+#include <vector>
+
+#include "katja/database.hpp"
+
namespace katja
{
+ struct package_identifier
+ {
+ const std::string name;
+ const std::string version;
+ const std::string architecture;
+ const std::string data;
+
+ std::string to_string() const;
+ };
+
+ class repository
+ {
+ public:
+ virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
+ };
}
diff --git a/include/katja/sbo.hpp b/include/katja/sbo.hpp
index ff16dd7..3c7a5d9 100644
--- a/include/katja/sbo.hpp
+++ b/include/katja/sbo.hpp
@@ -10,6 +10,8 @@
#include <filesystem>
#include <optional>
+#include "katja/repository.hpp"
+
namespace katja
{
struct info_file
@@ -24,6 +26,18 @@ namespace katja
const std::string homepage, const std::string& email, const std::string& maintainer);
};
+ class sbo_repository final : public repository
+ {
+ std::map<std::string, std::filesystem::path> info_paths;
+
+ public:
+ sbo_repository(const std::filesystem::path& repository_path);
+
+ std::vector<package_identifier> get_updates(const package_database& database) override;
+ };
+
std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath);
void search_for_slackbuilds(std::vector<info_file>& info_files, const std::filesystem::path& directory);
+ void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
+ const std::filesystem::path& directory);
}
diff --git a/katja/repository.cpp b/katja/repository.cpp
index e9a345c..270ffec 100644
--- a/katja/repository.cpp
+++ b/katja/repository.cpp
@@ -3,6 +3,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
+#include "katja/repository.hpp"
+
namespace katja
{
+ std::string package_identifier::to_string() const
+ {
+ std::string identifier;
+ const std::size_t total_size = this->name.size() + this->version.size()
+ + this->architecture.size() + this->data.size() + 3;
+
+ identifier.reserve(total_size);
+ identifier.append(this->name);
+ identifier.push_back(';');
+ identifier.append(this->version);
+ identifier.push_back(';');
+ identifier.append(this->architecture);
+ identifier.push_back(';');
+ identifier.append(this->data);
+
+ return identifier;
+ }
}
diff --git a/katja/sbo.cpp b/katja/sbo.cpp
index 161e834..f358b03 100644
--- a/katja/sbo.cpp
+++ b/katja/sbo.cpp
@@ -17,6 +17,35 @@ namespace katja
{
}
+ sbo_repository::sbo_repository(const std::filesystem::path& repository_path)
+ {
+ search_for_slackbuilds(this->info_paths, repository_path);
+ }
+
+ std::vector<package_identifier> sbo_repository::get_updates(const package_database& database)
+ {
+ std::vector<package_identifier> identifiers;
+
+ for (const auto& [package_name, package] : database)
+ {
+ auto looked_up_info_path = this->info_paths.find(package_name);
+
+ if (looked_up_info_path != this->info_paths.cend())
+ {
+ auto slackbuild_info = read_slackbuild_info(looked_up_info_path->second);
+
+ if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
+ {
+ identifiers.push_back({
+ slackbuild_info->program_name, slackbuild_info->version, package.architecture, "SBo"
+ });
+ }
+
+ }
+ }
+ return identifiers;
+ }
+
bool trim_info_line(std::string& info_value)
{
if (boost::algorithm::ends_with(info_value, "\""))
@@ -113,6 +142,23 @@ namespace katja
void search_for_slackbuilds(std::vector<info_file>& info_files, const std::filesystem::path& directory)
{
+ std::map<std::string, std::filesystem::path> info_paths;
+
+ search_for_slackbuilds(info_paths, directory);
+ for (const auto& [_, info_filepath] : info_paths)
+ {
+ auto slackbuild_info = read_slackbuild_info(info_filepath);
+
+ if (slackbuild_info.has_value())
+ {
+ info_files.emplace_back(std::move(slackbuild_info.value()));
+ }
+ }
+ }
+
+ void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
+ const std::filesystem::path& directory)
+ {
for (const auto& entry : std::filesystem::directory_iterator(directory))
{
std::filesystem::path entry_path = entry;
@@ -123,12 +169,7 @@ namespace katja
if (std::filesystem::exists(info_filepath))
{
- auto slackbuild_info = read_slackbuild_info(info_filepath);
-
- if (slackbuild_info.has_value())
- {
- info_files.emplace_back(std::move(slackbuild_info.value()));
- }
+ info_files.emplace(entry_path.filename(), info_filepath);
}
else if (std::filesystem::is_directory(entry_path))
{