This commit is contained in:
@@ -3,84 +3,101 @@
|
||||
* 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/database.hpp"
|
||||
module;
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <filesystem>
|
||||
|
||||
namespace katja
|
||||
export module katja.database;
|
||||
|
||||
export namespace katja
|
||||
{
|
||||
database_package database_package::create_database_package(const std::string& fullname)
|
||||
constexpr const char *database = "/var/lib/pkgtools/packages";
|
||||
|
||||
class database_package
|
||||
{
|
||||
std::string::const_reverse_iterator begin_iterator = std::crbegin(fullname);
|
||||
std::string::const_reverse_iterator end_iterator = begin_iterator;
|
||||
int minus_counter = 0;
|
||||
|
||||
std::string build_tag;
|
||||
std::string architecture;
|
||||
std::string version;
|
||||
|
||||
for (; begin_iterator != std::crend(fullname) && minus_counter < 3; ++begin_iterator)
|
||||
database_package(std::string&& name, std::string&& version,
|
||||
std::string&& architecture, std::string&& build_tag)
|
||||
: name(name), version(version), architecture(architecture), build_tag(build_tag)
|
||||
{
|
||||
if (*begin_iterator == '-')
|
||||
{
|
||||
if (minus_counter == 0)
|
||||
{
|
||||
build_tag = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
else if (minus_counter == 1)
|
||||
{
|
||||
architecture = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
else if (minus_counter == 2)
|
||||
{
|
||||
version = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
end_iterator = begin_iterator + 1;
|
||||
++minus_counter;
|
||||
}
|
||||
}
|
||||
return database_package(std::string(fullname.cbegin(), end_iterator.base()),
|
||||
std::move(version), std::move(architecture), std::move(build_tag));
|
||||
}
|
||||
|
||||
database_package::database_package(std::string&& name, std::string&& version,
|
||||
std::string&& architecture, std::string&& build_tag)
|
||||
: name(name), version(version), architecture(architecture), build_tag(build_tag)
|
||||
{
|
||||
}
|
||||
static database_package create_database_package(const std::string& fullname)
|
||||
{
|
||||
std::string::const_reverse_iterator begin_iterator = std::crbegin(fullname);
|
||||
std::string::const_reverse_iterator end_iterator = begin_iterator;
|
||||
int minus_counter = 0;
|
||||
|
||||
database_package::database_package(const std::string& fullname)
|
||||
: database_package(create_database_package(fullname))
|
||||
{
|
||||
}
|
||||
std::string build_tag;
|
||||
std::string architecture;
|
||||
std::string version;
|
||||
|
||||
bool database_package::operator<(const database_package& that) const
|
||||
{
|
||||
return this->name < that.name;
|
||||
}
|
||||
for (; begin_iterator != std::crend(fullname) && minus_counter < 3; ++begin_iterator)
|
||||
{
|
||||
if (*begin_iterator == '-')
|
||||
{
|
||||
if (minus_counter == 0)
|
||||
{
|
||||
build_tag = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
else if (minus_counter == 1)
|
||||
{
|
||||
architecture = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
else if (minus_counter == 2)
|
||||
{
|
||||
version = std::string(begin_iterator.base(), end_iterator.base());
|
||||
}
|
||||
end_iterator = begin_iterator + 1;
|
||||
++minus_counter;
|
||||
}
|
||||
}
|
||||
return database_package(std::string(fullname.cbegin(), end_iterator.base()),
|
||||
std::move(version), std::move(architecture), std::move(build_tag));
|
||||
}
|
||||
|
||||
bool database_package::operator>(const database_package& that) const
|
||||
{
|
||||
return this->name > that.name;
|
||||
}
|
||||
public:
|
||||
const std::string name;
|
||||
const std::string version;
|
||||
const std::string architecture;
|
||||
const std::string build_tag;
|
||||
|
||||
std::string database_package::to_string() const
|
||||
{
|
||||
std::string package_string;
|
||||
const std::size_t total_size = this->name.size() + this->version.size()
|
||||
+ this->architecture.size() + this->build_tag.size() + 3;
|
||||
database_package(const std::string& fullname)
|
||||
: database_package(create_database_package(fullname))
|
||||
{
|
||||
}
|
||||
|
||||
package_string.reserve(total_size);
|
||||
package_string.append(this->name);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->version);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->architecture);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->build_tag);
|
||||
bool operator<(const database_package& that) const
|
||||
{
|
||||
return this->name < that.name;
|
||||
}
|
||||
|
||||
return package_string;
|
||||
}
|
||||
bool operator>(const database_package& that) const
|
||||
{
|
||||
return this->name > that.name;
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
std::string package_string;
|
||||
const std::size_t total_size = this->name.size() + this->version.size()
|
||||
+ this->architecture.size() + this->build_tag.size() + 3;
|
||||
|
||||
package_string.reserve(total_size);
|
||||
package_string.append(this->name);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->version);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->architecture);
|
||||
package_string.push_back('-');
|
||||
package_string.append(this->build_tag);
|
||||
|
||||
return package_string;
|
||||
}
|
||||
};
|
||||
|
||||
using package_database = std::multimap<std::string, database_package>;
|
||||
|
||||
package_database read_installed_database()
|
||||
{
|
||||
|
||||
@@ -3,25 +3,48 @@
|
||||
* 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"
|
||||
module;
|
||||
|
||||
namespace katja
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
export module katja.repository;
|
||||
|
||||
import katja.database;
|
||||
|
||||
export namespace katja
|
||||
{
|
||||
std::string package_identifier::to_string() const
|
||||
struct package_identifier
|
||||
{
|
||||
std::string identifier;
|
||||
const std::size_t total_size = this->name.size() + this->version.size()
|
||||
+ this->architecture.size() + this->data.size() + 3;
|
||||
const std::string name;
|
||||
const std::string version;
|
||||
const std::string architecture;
|
||||
const std::string data;
|
||||
|
||||
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);
|
||||
std::string 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;
|
||||
|
||||
return identifier;
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class repository
|
||||
{
|
||||
public:
|
||||
virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
|
||||
virtual std::vector<package_identifier> search_names(const std::string& architecture,
|
||||
const std::string& needle) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
137
katja/sbo.cpp
137
katja/sbo.cpp
@@ -3,14 +3,61 @@
|
||||
* 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/.
|
||||
*/
|
||||
module;
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "katja/sbo.hpp"
|
||||
export module katja.sbo;
|
||||
|
||||
import katja.database;
|
||||
import katja.repository;
|
||||
|
||||
namespace katja
|
||||
{
|
||||
static
|
||||
bool trim_info_line(std::string& info_value)
|
||||
{
|
||||
if (boost::algorithm::ends_with(info_value, "\""))
|
||||
{
|
||||
info_value.pop_back();
|
||||
return false;
|
||||
}
|
||||
else if (boost::algorithm::ends_with(info_value, "\\"))
|
||||
{
|
||||
info_value.pop_back();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export struct info_file
|
||||
{
|
||||
const std::string program_name;
|
||||
const std::string version;
|
||||
const std::string homepage;
|
||||
const std::string email;
|
||||
const std::string maintainer;
|
||||
|
||||
info_file(const std::string& program_name, const std::string& version,
|
||||
const std::string homepage, const std::string& email, const std::string& maintainer)
|
||||
: program_name(program_name), version(version), homepage(homepage), email(email), maintainer(maintainer)
|
||||
{
|
||||
}
|
||||
|
||||
package_identifier identifier_for(const std::string& architecture)
|
||||
{
|
||||
return package_identifier{ this->program_name, this->version, architecture, "SBo" };
|
||||
}
|
||||
};
|
||||
export std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath);
|
||||
|
||||
static
|
||||
void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
|
||||
const std::filesystem::path& directory)
|
||||
@@ -50,76 +97,58 @@ namespace katja
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info_file::info_file(const std::string& program_name, const std::string& version,
|
||||
const std::string homepage, const std::string& email, const std::string& maintainer)
|
||||
: program_name(program_name), version(version), homepage(homepage), email(email), maintainer(maintainer)
|
||||
export namespace katja
|
||||
{
|
||||
class sbo_repository final : public repository
|
||||
{
|
||||
}
|
||||
std::map<std::string, std::filesystem::path> info_paths;
|
||||
|
||||
package_identifier info_file::identifier_for(const std::string& architecture)
|
||||
{
|
||||
return package_identifier{ this->program_name, this->version, architecture, "SBo" };
|
||||
}
|
||||
|
||||
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)
|
||||
public:
|
||||
sbo_repository(const std::filesystem::path& repository_path)
|
||||
{
|
||||
auto looked_up_info_path = this->info_paths.find(package_name);
|
||||
search_for_slackbuilds(this->info_paths, repository_path);
|
||||
}
|
||||
|
||||
if (looked_up_info_path != this->info_paths.cend())
|
||||
std::vector<package_identifier> get_updates(const package_database& database) override
|
||||
{
|
||||
std::vector<package_identifier> identifiers;
|
||||
|
||||
for (const auto& [package_name, package] : database)
|
||||
{
|
||||
auto slackbuild_info = read_slackbuild_info(looked_up_info_path->second);
|
||||
auto looked_up_info_path = this->info_paths.find(package_name);
|
||||
|
||||
if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
|
||||
if (looked_up_info_path != this->info_paths.cend())
|
||||
{
|
||||
identifiers.push_back(slackbuild_info->identifier_for(package.architecture));
|
||||
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->identifier_for(package.architecture));
|
||||
}
|
||||
}
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
std::vector<package_identifier> sbo_repository::search_names(const std::string& architecture,
|
||||
const std::string& needle)
|
||||
{
|
||||
std::vector<package_identifier> identifiers;
|
||||
|
||||
for (const auto& [package_name, info_path] : this->info_paths)
|
||||
std::vector<package_identifier> search_names(const std::string& architecture,
|
||||
const std::string& needle) override
|
||||
{
|
||||
if (package_name.find(needle) != std::string::npos)
|
||||
std::vector<package_identifier> identifiers;
|
||||
|
||||
for (const auto& [package_name, info_path] : this->info_paths)
|
||||
{
|
||||
auto slackbuild_info = read_slackbuild_info(info_path);
|
||||
if (package_name.find(needle) != std::string::npos)
|
||||
{
|
||||
auto slackbuild_info = read_slackbuild_info(info_path);
|
||||
|
||||
identifiers.push_back(slackbuild_info->identifier_for(architecture));
|
||||
identifiers.push_back(slackbuild_info->identifier_for(architecture));
|
||||
}
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
static
|
||||
bool trim_info_line(std::string& info_value)
|
||||
{
|
||||
if (boost::algorithm::ends_with(info_value, "\""))
|
||||
{
|
||||
info_value.pop_back();
|
||||
return false;
|
||||
}
|
||||
else if (boost::algorithm::ends_with(info_value, "\\"))
|
||||
{
|
||||
info_value.pop_back();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user