diff options
80 files changed, 2322 insertions, 1996 deletions
diff --git a/gentoobrowse-api/api/impl.cpp b/gentoobrowse-api/api/impl.cpp index 9c21c98..762e9d6 100644 --- a/gentoobrowse-api/api/impl.cpp +++ b/gentoobrowse-api/api/impl.cpp @@ -1,11 +1,11 @@ -#include <maintenance.h> #include <compileTimeFormatter.h> +#include <maintenance.h> namespace Gentoo { AdHocFormatter(GitErrorMessage, "Git Error: %?: %? (code %?, class %?)"); - void GitError::ice_print(std::ostream & s) const + void + GitError::ice_print(std::ostream & s) const { GitErrorMessage::write(s, operation, message, errorCode, errorClass); } } - diff --git a/gentoobrowse-api/client/helpers.h b/gentoobrowse-api/client/helpers.h index 76f8148..96399d2 100644 --- a/gentoobrowse-api/client/helpers.h +++ b/gentoobrowse-api/client/helpers.h @@ -1,14 +1,15 @@ #ifndef GENTOOBROWSE_CLIENT_HELPERS_H #define GENTOOBROWSE_CLIENT_HELPERS_H -#include <map> #include <Ice/AsyncResult.h> +#include <Ice/ObjectAdapter.h> +#include <future> +#include <map> #include <mutex> template<typename Key, typename Target, typename Collection, typename Proxy> std::map<Key, Target> -asyncMapRelated(const Collection & collection, const Proxy & p, - Key Collection::value_type::element_type::* member, +asyncMapRelated(const Collection & collection, const Proxy & p, Key Collection::value_type::element_type::*member, std::future<Target> (Proxy::element_type::*b)(Key, const ::Ice::Context &)) { std::map<Key, Target> rtn; @@ -16,15 +17,13 @@ asyncMapRelated(const Collection & collection, const Proxy & p, for (const auto & item : collection) { Key v = item.get()->*member; if (jobs.find(v) == jobs.end()) { - jobs.insert({ v, (p.get()->*b)(v, Ice::noExplicitContext) }); + jobs.insert({v, (p.get()->*b)(v, Ice::noExplicitContext)}); } } for (auto & j : jobs) { - rtn.insert({ j.first, j.second.get() }); + rtn.insert({j.first, j.second.get()}); } return rtn; } - #endif - diff --git a/gentoobrowse-api/client/main.cpp b/gentoobrowse-api/client/main.cpp index d542188..56f0a4b 100644 --- a/gentoobrowse-api/client/main.cpp +++ b/gentoobrowse-api/client/main.cpp @@ -1,9 +1,9 @@ -#include "stdio.h" #include "main.h" -#include <portage.h> -#include <plugins.impl.h> +#include "stdio.h" #include <Ice/Ice.h> #include <boost/program_options.hpp> +#include <plugins.impl.h> +#include <portage.h> namespace po = boost::program_options; INSTANTIATEPLUGINOF(Module); @@ -15,12 +15,10 @@ main(int c, char ** v) std::string module; std::vector<std::string> args; po::options_description opts("Gentoo Browse Client options"); - opts.add_options() - ("endpoint", po::value(&endpoint)->default_value("tcp -h gentoobrowse.randomdan.homeip.net -p 9001"), "Service endpoint") - ("module", po::value(&module), "Module") - ("args", po::value(&args), "Module options") - ("help,h", "Show help") - ; + opts.add_options()("endpoint", + po::value(&endpoint)->default_value("tcp -h gentoobrowse.randomdan.homeip.net -p 9001"), + "Service endpoint")("module", po::value(&module), "Module")("args", po::value(&args), "Module options")( + "help,h", "Show help"); po::positional_options_description pod; pod.add("module", 1).add("args", -1); po::variables_map vm; @@ -41,4 +39,3 @@ main(int c, char ** v) ic->destroy(); return 0; } - diff --git a/gentoobrowse-api/client/main.h b/gentoobrowse-api/client/main.h index 1f88081..9c7ccef 100644 --- a/gentoobrowse-api/client/main.h +++ b/gentoobrowse-api/client/main.h @@ -1,15 +1,14 @@ #ifndef GENTOO_MAIN_H #define GENTOO_MAIN_H -#include <vector> -#include <string> #include <plugins.h> #include <portage.h> +#include <string> +#include <vector> class Module : public AdHoc::AbstractPluginImplementation { - public: - virtual void run(const Gentoo::PortagePrxPtr &, const std::vector<std::string> &) const = 0; +public: + virtual void run(const Gentoo::PortagePrxPtr &, const std::vector<std::string> &) const = 0; }; #endif - diff --git a/gentoobrowse-api/client/search.cpp b/gentoobrowse-api/client/search.cpp index 448643b..9d1c7b4 100644 --- a/gentoobrowse-api/client/search.cpp +++ b/gentoobrowse-api/client/search.cpp @@ -1,22 +1,23 @@ -#include <plugins.h> -#include <fprintbf.h> -#include <boost/algorithm/string/join.hpp> -#include "main.h" #include "helpers.h" +#include "main.h" +#include <boost/algorithm/string/join.hpp> +#include <fprintbf.h> +#include <plugins.h> class search : public Module { - public: - void run(const Gentoo::PortagePrxPtr & p, const std::vector<std::string> & a) const override - { - auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); - auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, - (std::future<Gentoo::CategoryPtr> (Gentoo::PortagePrx::*)(Ice::Int, const ::Ice::Context &))&Gentoo::PortagePrx::getCategoryAsync); - fprintbf(stdout, "Found %d packages:\n", pkgs.size()); - for (const auto & pkg : pkgs) { - fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); - } +public: + void + run(const Gentoo::PortagePrxPtr & p, const std::vector<std::string> & a) const override + { + auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); + auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, + (std::future<Gentoo::CategoryPtr>(Gentoo::PortagePrx::*)(Ice::Int, const ::Ice::Context &)) + & Gentoo::PortagePrx::getCategoryAsync); + fprintbf(stdout, "Found %d packages:\n", pkgs.size()); + for (const auto & pkg : pkgs) { + fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); } + } }; PLUGIN(search, Module); - diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp index 8a3abbd..09268b8 100644 --- a/gentoobrowse-api/domain/converters.cpp +++ b/gentoobrowse-api/domain/converters.cpp @@ -1,20 +1,17 @@ -#include <portage-models.h> #include "converters.h" #include "converters.impl.h" #include "unpackPqTextArray.h" -#include <string> #include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/split.hpp> +#include <portage-models.h> +#include <string> namespace Slicer { - template<typename T> - PqArray<T>::PqArray(std::vector<T> * l) : - ModelPartForSequence<std::vector<T>>(l) - { - } + template<typename T> PqArray<T>::PqArray(std::vector<T> * l) : ModelPartForSequence<std::vector<T>>(l) { } template<typename T> - void PqArray<T>::SetValue(ValueSource && s) + void + PqArray<T>::SetValue(ValueSource && s) { std::string in; s.set(in); @@ -44,4 +41,3 @@ namespace Slicer { return boost::gregorian::to_sql_string(s.date()); } } - diff --git a/gentoobrowse-api/domain/converters.h b/gentoobrowse-api/domain/converters.h index be1a522..07188fa 100644 --- a/gentoobrowse-api/domain/converters.h +++ b/gentoobrowse-api/domain/converters.h @@ -1,29 +1,25 @@ #ifndef something #define something -#include <portage-models.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <visibility.h> +#include <portage-models.h> #include <slicer/modelPartsTypes.impl.h> +#include <visibility.h> namespace Slicer { - template<typename T> - class DLL_PUBLIC PqArray : public ModelPartForSequence<std::vector<T>> { - public: - PqArray(std::vector<T> *); + template<typename T> class DLL_PUBLIC PqArray : public ModelPartForSequence<std::vector<T>> { + public: + PqArray(std::vector<T> *); - void SetValue(ValueSource &&) override; - bool GetValue(ValueTarget &&) override; + void SetValue(ValueSource &&) override; + bool GetValue(ValueTarget &&) override; }; DLL_PUBLIC - boost::posix_time::ptime - shortDateToPosixTime(const std::string & s); + boost::posix_time::ptime shortDateToPosixTime(const std::string & s); DLL_PUBLIC - std::string - posixTimeToShortDate(const boost::posix_time::ptime & s); + std::string posixTimeToShortDate(const boost::posix_time::ptime & s); } #endif - diff --git a/gentoobrowse-api/domain/converters.impl.h b/gentoobrowse-api/domain/converters.impl.h index 894d0de..6ba15fa 100644 --- a/gentoobrowse-api/domain/converters.impl.h +++ b/gentoobrowse-api/domain/converters.impl.h @@ -2,24 +2,21 @@ #define GENTOOBROWSE_API_DOMAIN_CONVERTERS_IMPL_H #include "unpackPqTextArray.h" +#include <boost/lexical_cast.hpp> namespace Slicer { - template <typename T> - class UnpackPqTextArrayInto : public UnpackPqTextArray { - public: - UnpackPqTextArrayInto(std::istream & s, std::vector<T> & l) : - UnpackPqTextArray(s), - list(l) - { - } + template<typename T> class UnpackPqTextArrayInto : public UnpackPqTextArray { + public: + UnpackPqTextArrayInto(std::istream & s, std::vector<T> & l) : UnpackPqTextArray(s), list(l) { } - virtual void consume(const std::string & s) override - { - list.push_back(boost::lexical_cast<T>(s)); - } + virtual void + consume(const std::string & s) override + { + list.push_back(boost::lexical_cast<T>(s)); + } - private: - std::vector<T> & list; + private: + std::vector<T> & list; }; std::string @@ -45,7 +42,7 @@ namespace Slicer { } } - template <typename T> + template<typename T> std::vector<T> unpackPqArray(const std::string & s) { @@ -77,4 +74,3 @@ namespace Slicer { } #endif - diff --git a/gentoobrowse-api/domain/unpackPqTextArray.h b/gentoobrowse-api/domain/unpackPqTextArray.h index 5f639b4..b1b2857 100644 --- a/gentoobrowse-api/domain/unpackPqTextArray.h +++ b/gentoobrowse-api/domain/unpackPqTextArray.h @@ -3,25 +3,23 @@ #include <portage-models.h> #ifndef yyFlexLexer -#define yyFlexLexer pqBaseFlexLexer -#include <FlexLexer.h> +# define yyFlexLexer pqBaseFlexLexer +# include <FlexLexer.h> #endif namespace Slicer { class UnpackPqTextArray : public yyFlexLexer { - public: - UnpackPqTextArray(std::istream &); - virtual ~UnpackPqTextArray() = default; + public: + UnpackPqTextArray(std::istream &); + virtual ~UnpackPqTextArray() = default; - int yylex() override; - void LexerError(const char * msg) override; - virtual void consume(const std::string &) = 0; + int yylex() override; + void LexerError(const char * msg) override; + virtual void consume(const std::string &) = 0; - private: - std::string buffer; + private: + std::string buffer; }; } #endif - - diff --git a/gentoobrowse-api/etc/icebox.config b/gentoobrowse-api/etc/icebox.config index 688eea5..02170c4 100644 --- a/gentoobrowse-api/etc/icebox.config +++ b/gentoobrowse-api/etc/icebox.config @@ -1,6 +1,4 @@ -IceBox.Service.GentooBrowseAPI=gentoobrowse-service:createIceTrayService -IceBox.InheritProperties=1 -GentooBrowseAPI.ThreadPool.Size=8 -GentooBrowseAPI.ThreadPool.SizeMax=50 -GentooBrowseAPI.Database.ConnectionString="user=postgres dbname=gentoo" -GentooBrowseAPI.Endpoints="tcp -p 9001" +IceBox.Service.GentooBrowseAPI = gentoobrowse - service : createIceTrayService IceBox.InheritProperties + = 1 GentooBrowseAPI.ThreadPool.Size = 8 GentooBrowseAPI.ThreadPool.SizeMax + = 50 GentooBrowseAPI.Database.ConnectionString = "user=postgres dbname=gentoo" GentooBrowseAPI.Endpoints + = "tcp -p 9001" diff --git a/gentoobrowse-api/etc/service.conf b/gentoobrowse-api/etc/service.conf index ee83ffd..13e81ff 100644 --- a/gentoobrowse-api/etc/service.conf +++ b/gentoobrowse-api/etc/service.conf @@ -1,4 +1 @@ -[Service] -User=portage -Group=portage -NotifyAccess=main +[Service] User = portage Group = portage NotifyAccess = main diff --git a/gentoobrowse-api/service/changeSet.h b/gentoobrowse-api/service/changeSet.h index c13573c..ab83656 100644 --- a/gentoobrowse-api/service/changeSet.h +++ b/gentoobrowse-api/service/changeSet.h @@ -1,10 +1,10 @@ #ifndef CHANGESET_H #define CHANGESET_H -#include <git2/diff.h> -#include <portage-models.h> #include <filesystem> +#include <git2/diff.h> #include <map> +#include <portage-models.h> namespace Gentoo { namespace Service { @@ -17,4 +17,3 @@ namespace Gentoo { } #endif - diff --git a/gentoobrowse-api/service/depend.cpp b/gentoobrowse-api/service/depend.cpp index c17b37a..15588d8 100644 --- a/gentoobrowse-api/service/depend.cpp +++ b/gentoobrowse-api/service/depend.cpp @@ -2,25 +2,30 @@ #include <boost/algorithm/string/split.hpp> #include <lexer-regex.h> -AdHoc::Lexer::PatternPtr WhenUse_Begin(AdHoc::LexerMatchers::regex("\\s*(!?[[:alnum:]-_@]+)\\?\\s*\\(\\s*", G_REGEX_OPTIMIZE)); +AdHoc::Lexer::PatternPtr WhenUse_Begin( + AdHoc::LexerMatchers::regex("\\s*(!?[[:alnum:]-_@]+)\\?\\s*\\(\\s*", G_REGEX_OPTIMIZE)); AdHoc::Lexer::PatternPtr WhenUse_End(AdHoc::LexerMatchers::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE)); AdHoc::Lexer::PatternPtr Or_Begin(AdHoc::LexerMatchers::regex("\\s*\\|\\|\\s*\\(\\s*", G_REGEX_OPTIMIZE)); AdHoc::Lexer::PatternPtr Or_Group(AdHoc::LexerMatchers::regex("\\s*\\(\\s*", G_REGEX_OPTIMIZE)); AdHoc::Lexer::PatternPtr Or_End(AdHoc::LexerMatchers::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE)); -AdHoc::Lexer::PatternPtr AtomSpec(AdHoc::LexerMatchers::regex("\\s*" +AdHoc::Lexer::PatternPtr AtomSpec(AdHoc::LexerMatchers::regex( + "\\s*" "([[:punct:]]+)?" // op "([[:alnum:]-]+)\\/" // cat "([^ ]+)" // package "(-([0-9][.0-9]*[[:alpha:]]?\\*?((_(alpha|beta|pre|rc|p))?[[:digit:]]*)*(-r[[:digit:]]+)?))?" // version "(:([^/ []+(\\/[^ []+)?))?" // slot - "(\\[([^]]+)\\])?(\\s+|$)", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_UNGREEDY))); // use + "(\\[([^]]+)\\])?(\\s+|$)", + (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_UNGREEDY))); // use const std::string InWhen("InWhen"); const std::string InOr("InOr"); namespace Portage { namespace Utils { - template<typename T, typename Y> Ice::optional<T> iuo(const std::optional<Y> & x) + template<typename T, typename Y> + Ice::optional<T> + iuo(const std::optional<Y> & x) { if (x) { return Ice::optional<T>(*x); @@ -28,53 +33,59 @@ namespace Portage { return Ice::optional<T>(); } - template<typename T, typename Y> std::vector<T> split(const std::optional<Y> & x) + template<typename T, typename Y> + std::vector<T> + split(const std::optional<Y> & x) { std::vector<T> rtn; if (x) { - boost::algorithm::split(rtn, *x, [](auto c) { return c == ','; }); + boost::algorithm::split(rtn, *x, [](auto c) { + return c == ','; + }); std::sort(rtn.begin(), rtn.end()); } return rtn; } Depend::Depend() : - AdHoc::Lexer({ - // use? ( - { { InitialState, InWhen, InOr }, WhenUse_Begin, [this](auto es) { - es->pushState(InWhen); - when.push_back(*es->pattern()->match(1)); - } }, - // ) - { { InWhen }, WhenUse_End, [this](auto es) { - es->popState(); - when.pop_back(); - } }, - // || ( - { { InitialState, InWhen, InOr }, Or_Begin, [](auto es) { - es->pushState(InOr); - } }, - // ( - { { InitialState, InWhen, InOr }, Or_Group, [](auto es) { - es->pushState(InOr); - } }, - // ) - { { InOr }, Or_End, [](auto es) { - es->popState(); - } }, - // [op]some-cat/package[-version][:slot][uses] - { { InitialState, InWhen, InOr }, AtomSpec, [this](auto es) { - ds.push_back(std::make_shared<Gentoo::Dependency>( - when, - iuo<std::string>(es->pattern()->match(1)), // op - *es->pattern()->match(2), // category - *es->pattern()->match(3), // package - iuo<std::string>(es->pattern()->match(5)), // version - iuo<std::string>(es->pattern()->match(11)), // slot - split<std::string>(es->pattern()->match(14)) // use - )); - } } - }) + AdHoc::Lexer({// use? ( + {{InitialState, InWhen, InOr}, WhenUse_Begin, + [this](auto es) { + es->pushState(InWhen); + when.push_back(*es->pattern()->match(1)); + }}, + // ) + {{InWhen}, WhenUse_End, + [this](auto es) { + es->popState(); + when.pop_back(); + }}, + // || ( + {{InitialState, InWhen, InOr}, Or_Begin, + [](auto es) { + es->pushState(InOr); + }}, + // ( + {{InitialState, InWhen, InOr}, Or_Group, + [](auto es) { + es->pushState(InOr); + }}, + // ) + {{InOr}, Or_End, + [](auto es) { + es->popState(); + }}, + // [op]some-cat/package[-version][:slot][uses] + {{InitialState, InWhen, InOr}, AtomSpec, [this](auto es) { + ds.push_back(std::make_shared<Gentoo::Dependency>(when, + iuo<std::string>(es->pattern()->match(1)), // op + *es->pattern()->match(2), // category + *es->pattern()->match(3), // package + iuo<std::string>(es->pattern()->match(5)), // version + iuo<std::string>(es->pattern()->match(11)), // slot + split<std::string>(es->pattern()->match(14)) // use + )); + }}}) { } @@ -87,4 +98,3 @@ namespace Portage { } } } - diff --git a/gentoobrowse-api/service/depend.h b/gentoobrowse-api/service/depend.h index beeace6..7a6af44 100644 --- a/gentoobrowse-api/service/depend.h +++ b/gentoobrowse-api/service/depend.h @@ -2,23 +2,22 @@ #define GENTOOBROWSE_SERVICE_DEPEND_H #include <istream> -#include <vector> -#include <portage-models.h> #include <lexer.h> +#include <portage-models.h> +#include <vector> namespace Portage { namespace Utils { class Depend : AdHoc::Lexer { - private: - Depend(); - Gentoo::StringList when; + private: + Depend(); + Gentoo::StringList when; - public: - static std::vector<Gentoo::DependencyPtr> parse(const std::string_view &); - std::vector<Gentoo::DependencyPtr> ds; + public: + static std::vector<Gentoo::DependencyPtr> parse(const std::string_view &); + std::vector<Gentoo::DependencyPtr> ds; }; } } #endif - diff --git a/gentoobrowse-api/service/main.cpp b/gentoobrowse-api/service/main.cpp index 91ba9d4..d79f13b 100644 --- a/gentoobrowse-api/service/main.cpp +++ b/gentoobrowse-api/service/main.cpp @@ -1,48 +1,49 @@ -#include <Ice/Initialize.h> -#include <icetrayService.h> -#include "portageimpl.h" -#include "usersimpl.h" +#include "mailServer.h" #include "maintenanceimpl.h" #include "notificationsimpl.h" -#include "mailServer.h" +#include "portageimpl.h" +#include "usersimpl.h" +#include <Ice/Initialize.h> #include <icecube.h> +#include <icetrayService.h> +#include <git2.h> #include <libexslt/exslt.h> #include <libxslt/transform.h> -#include <git2.h> namespace Gentoo { -namespace Service { -class Api : public IceTray::Service { - public: - Api() - { - xmlInitParser(); - exsltRegisterAll(); - git_libgit2_init(); - } + namespace Service { + class Api : public IceTray::Service { + public: + Api() + { + xmlInitParser(); + exsltRegisterAll(); + git_libgit2_init(); + } - ~Api() - { - xsltCleanupGlobals(); - xmlCleanupParser(); - git_libgit2_shutdown(); - } + ~Api() + { + xsltCleanupGlobals(); + xmlCleanupParser(); + git_libgit2_shutdown(); + } - void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adp) override - { - auto db = getConnectionPool(ic, "postgresql", "GentooBrowseAPI"); - auto props = ic->getProperties(); - IceTray::Cube::addObject<Gentoo::Portage, Portage>(adp, "portage", db); - IceTray::Cube::addObject<Gentoo::Maintenance, Maintenance>(adp, "maintenance", db, ic, props); - IceTray::Cube::addObject<Gentoo::Users, Users>(adp, "users", db); - IceTray::Cube::add<Gentoo::Notifications, Notifications>(); - IceTray::Cube::add<IceTray::Mail::MailServer, IceTray::Mail::LibesmtpMailServer>( - props->getPropertyWithDefault("GentooBrowseAPI.MailServer", "localhost:25")); - } -}; + void + addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, + const Ice::ObjectAdapterPtr & adp) override + { + auto db = getConnectionPool(ic, "postgresql", "GentooBrowseAPI"); + auto props = ic->getProperties(); + IceTray::Cube::addObject<Gentoo::Portage, Portage>(adp, "portage", db); + IceTray::Cube::addObject<Gentoo::Maintenance, Maintenance>(adp, "maintenance", db, ic, props); + IceTray::Cube::addObject<Gentoo::Users, Users>(adp, "users", db); + IceTray::Cube::add<Gentoo::Notifications, Notifications>(); + IceTray::Cube::add<IceTray::Mail::MailServer, IceTray::Mail::LibesmtpMailServer>( + props->getPropertyWithDefault("GentooBrowseAPI.MailServer", "localhost:25")); + } + }; -NAMEDFACTORY("default", Api, IceTray::ServiceFactory); -} + NAMEDFACTORY("default", Api, IceTray::ServiceFactory); + } } - diff --git a/gentoobrowse-api/service/maintenance/abstractFileProcessor.cpp b/gentoobrowse-api/service/maintenance/abstractFileProcessor.cpp index d63d01a..6c74ecb 100644 --- a/gentoobrowse-api/service/maintenance/abstractFileProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/abstractFileProcessor.cpp @@ -5,9 +5,7 @@ INSTANTIATEVOIDFACTORY(Gentoo::Service::AbstractFileProcessor); namespace Gentoo { namespace Service { - AbstractFileProcessor::~AbstractFileProcessor() - { - } + AbstractFileProcessor::~AbstractFileProcessor() { } void AbstractFileProcessor::prepare(DB::Connection *) @@ -30,4 +28,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/maintenance/abstractFileProcessor.h b/gentoobrowse-api/service/maintenance/abstractFileProcessor.h index cd44536..0ffdcce 100644 --- a/gentoobrowse-api/service/maintenance/abstractFileProcessor.h +++ b/gentoobrowse-api/service/maintenance/abstractFileProcessor.h @@ -1,32 +1,36 @@ #ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_ABSTRACTPROC_H #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_ABSTRACTPROC_H +#include "changeSet.h" #include <connection.h> -#include <maintenance.h> -#include <filesystem> #include <factory.h> -#include "changeSet.h" +#include <filesystem> +#include <maintenance.h> namespace Gentoo { namespace Service { typedef std::vector<std::string> PathParts; class AbstractFileProcessor { - public: - virtual ~AbstractFileProcessor() = 0; - - virtual unsigned char phase() const = 0; - virtual unsigned char order() const = 0; - virtual bool match(const PathParts & pp) const = 0; - - virtual void prepare(DB::Connection *); - virtual void apply(DB::Connection *, ChangeSet &); - virtual void phaseEnd(DB::Connection *, ChangeSet &); - virtual void tidy(DB::Connection *); - - virtual void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) = 0; - virtual void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) = 0; - virtual void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) = 0; + public: + virtual ~AbstractFileProcessor() = 0; + + virtual unsigned char phase() const = 0; + virtual unsigned char order() const = 0; + virtual bool match(const PathParts & pp) const = 0; + + virtual void prepare(DB::Connection *); + virtual void apply(DB::Connection *, ChangeSet &); + virtual void phaseEnd(DB::Connection *, ChangeSet &); + virtual void tidy(DB::Connection *); + + virtual void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) + = 0; + virtual void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) + = 0; + virtual void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) = 0; }; typedef std::shared_ptr<AbstractFileProcessor> FileProcessorPtr; typedef AdHoc::Factory<AbstractFileProcessor> FileProcessorFactory; @@ -34,4 +38,3 @@ namespace Gentoo { } #endif - diff --git a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp index 5f5b41a..f452390 100644 --- a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp @@ -1,9 +1,9 @@ #include "categoryMetaProcessor.h" -#include <modifycommand.h> +#include "utils/dbUtils.h" +#include "utils/xmlUtils.h" #include <fileUtils.h> +#include <modifycommand.h> #include <optionalUtils.h> -#include "utils/xmlUtils.h" -#include "utils/dbUtils.h" #include <sql/maintenance/categoryMetaUpdate.sql.h> namespace U = Gentoo::Utils; @@ -12,27 +12,38 @@ using namespace AdHoc::FileUtils; namespace Gentoo { namespace Service { - unsigned char CategoryMetaProcessor::phase() const { return 2; } - unsigned char CategoryMetaProcessor::order() const { return 2; } - bool CategoryMetaProcessor::match(const PathParts & pp) const + unsigned char + CategoryMetaProcessor::phase() const + { + return 2; + } + unsigned char + CategoryMetaProcessor::order() const + { + return 2; + } + bool + CategoryMetaProcessor::match(const PathParts & pp) const { return (pp.size() == 2 && pp[1] == "metadata.xml"); } void - CategoryMetaProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + CategoryMetaProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } void - CategoryMetaProcessor::modified(DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) + CategoryMetaProcessor::modified( + DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) { auto m = sql::maintenance::categoryMetaUpdate.modify(dbc); U::XmlDoc md(path); m->bindParamS(0, - md.getXPathValue("/catmetadata/longdescription[@lang='en']/text()") / - md.getXPathValue("/catmetadata/longdescription[1]/text()")); + md.getXPathValue("/catmetadata/longdescription[@lang='en']/text()") + / md.getXPathValue("/catmetadata/longdescription[1]/text()")); m->bindParamS(1, fn.front()); m->execute(); } @@ -48,4 +59,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::CategoryMetaProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.h b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.h index 0306f3e..8915611 100644 --- a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.h @@ -7,17 +7,18 @@ namespace Gentoo { namespace Service { class CategoryMetaProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index 905ba95..6bcf149 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -1,29 +1,28 @@ #include "ebuildMetaProcessor.h" -#include <modifycommand.h> -#include <sqlWriter.h> -#include <selectcommandUtil.impl.h> -#include <sqlWriter.h> -#include <boost/algorithm/string/join.hpp> -#include <boost/date_time/posix_time/conversion.hpp> -#include <glibmm/regex.h> -#include <tablepatch.h> -#include <optionalUtils.h> #include "depend.h" #include "utils/dbUtils.h" #include "utils/ebuildCacheParser.h" #include "utils/splitEbuildProps.h" +#include <boost/algorithm/string/join.hpp> +#include <boost/date_time/posix_time/conversion.hpp> +#include <glibmm/regex.h> +#include <modifycommand.h> +#include <optionalUtils.h> +#include <selectcommandUtil.impl.h> #include <sql/maintenance/categoryInsert.sql.h> -#include <sql/maintenance/packageInsert.sql.h> -#include <sql/maintenance/packageDescUpdate.sql.h> -#include <sql/maintenance/packagePrune.sql.h> #include <sql/maintenance/categoryPrune.sql.h> -#include <sql/maintenance/ebuildInsert.sql.h> -#include <sql/maintenance/ebuildUpdate.sql.h> +#include <sql/maintenance/ebuildArchsInsert.sql.h> #include <sql/maintenance/ebuildDelete.sql.h> #include <sql/maintenance/ebuildDeps.sql.h> +#include <sql/maintenance/ebuildInsert.sql.h> #include <sql/maintenance/ebuildRDeps.sql.h> +#include <sql/maintenance/ebuildUpdate.sql.h> #include <sql/maintenance/ebuildUsesInsert.sql.h> -#include <sql/maintenance/ebuildArchsInsert.sql.h> +#include <sql/maintenance/packageDescUpdate.sql.h> +#include <sql/maintenance/packageInsert.sql.h> +#include <sql/maintenance/packagePrune.sql.h> +#include <sqlWriter.h> +#include <tablepatch.h> namespace U = Gentoo::Utils; using namespace AdHoc; @@ -33,20 +32,27 @@ static Glib::RefPtr<Glib::Regex> packageVersion = Glib::Regex::create("^(.+)-([0 namespace Gentoo { namespace Service { - EbuildMetaProcessor::EbuildMetaProcessor() : - ebuildIds("ebuildId") + EbuildMetaProcessor::EbuildMetaProcessor() : ebuildIds("ebuildId") { } + + unsigned char + EbuildMetaProcessor::phase() const { + return 2; } - - unsigned char EbuildMetaProcessor::phase() const { return 2; } - unsigned char EbuildMetaProcessor::order() const { return 1; } - bool EbuildMetaProcessor::match(const PathParts & pp) const + unsigned char + EbuildMetaProcessor::order() const + { + return 1; + } + bool + EbuildMetaProcessor::match(const PathParts & pp) const { return (pp.size() == 4 && pp[0] == "metadata" && pp[1] == "md5-cache"); } void - EbuildMetaProcessor::created(DB::Connection * dbc, int64_t repoId, const StringList & fn, const std::filesystem::path & path) + EbuildMetaProcessor::created( + DB::Connection * dbc, int64_t repoId, const StringList & fn, const std::filesystem::path & path) { Glib::MatchInfo matches; const Glib::ustring pv = fn[3]; @@ -78,14 +84,15 @@ namespace Gentoo { m->bindParamI(5, repoId); m->bindParamS(6, categoryName); m->bindParamS(7, packageName); - m->forEachRow<int64_t, bool, int64_t>([this,dbc,&ecp] (auto ebuildId, auto newest, auto packageId) { - this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); - }); + m->forEachRow<int64_t, bool, int64_t>([this, dbc, &ecp](auto ebuildId, auto newest, auto packageId) { + this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); + }); } } void - EbuildMetaProcessor::modified(DB::Connection * dbc, int64_t repoId, const StringList & fn, const std::filesystem::path & path) + EbuildMetaProcessor::modified( + DB::Connection * dbc, int64_t repoId, const StringList & fn, const std::filesystem::path & path) { Glib::MatchInfo matches; const Glib::ustring pv = fn[3]; @@ -99,35 +106,39 @@ namespace Gentoo { m->bindParamS(4, fn[2]); // category m->bindParamS(5, matches.fetch(1)); // package m->bindParamS(6, matches.fetch(2)); // version - m->forEachRow<int64_t, bool, int64_t>([this,dbc,&ecp] (auto ebuildId, auto newest, auto packageId) { - this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); - }); + m->forEachRow<int64_t, bool, int64_t>([this, dbc, &ecp](auto ebuildId, auto newest, auto packageId) { + this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); + }); } } void EbuildMetaProcessor::prepare(DB::Connection * dbc) { - depInsert = Utils::Database::namedTemp(dbc, "tmpEbuildDeps", { - { "ebuildId", "int" }, // 1 - { "runtime", "boolean" }, // 5 - { "category", "text" }, // 0 - { "package", "text" }, // 4 - { "version", "text" }, // 7 - { "slot", "text" }, // 6 - { "flags", "text" }, // 2 - { "op", "text" } // 3 - }).second; - Utils::Database::namedTemp(dbc, "tmpEbuildUses", { - { "ebuildId", "int" }, - { "use", "text" }, - { "defaultflag", "boolean" }, - }); + depInsert = Utils::Database::namedTemp(dbc, "tmpEbuildDeps", + { + {"ebuildId", "int"}, // 1 + {"runtime", "boolean"}, // 5 + {"category", "text"}, // 0 + {"package", "text"}, // 4 + {"version", "text"}, // 7 + {"slot", "text"}, // 6 + {"flags", "text"}, // 2 + {"op", "text"} // 3 + }) + .second; + Utils::Database::namedTemp(dbc, "tmpEbuildUses", + { + {"ebuildId", "int"}, + {"use", "text"}, + {"defaultflag", "boolean"}, + }); useInsert = sql::maintenance::ebuildUsesInsert.modify(dbc); - Utils::Database::namedTemp(dbc, "tmpEbuildArchs", { - { "ebuildId", "int" }, - { "arch", "text" }, - }); + Utils::Database::namedTemp(dbc, "tmpEbuildArchs", + { + {"ebuildId", "int"}, + {"arch", "text"}, + }); archInsert = sql::maintenance::ebuildArchsInsert.modify(dbc); } @@ -138,8 +149,8 @@ namespace Gentoo { { dbc->execute("CREATE INDEX idxTmpEbuildDeps ON tmpEbuildDeps(ebuildId, runtime)"); DB::TablePatch t; - t.pk = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; - t.cols = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; + t.pk = {"ebuildid", "packageid", "versionspec", "flags", "slot", "op"}; + t.cols = {"ebuildid", "packageid", "versionspec", "flags", "slot", "op"}; t.where = &ebuildIds; DB::StaticSqlWriter sb(sql::maintenance::ebuildDeps.getSql()); @@ -157,8 +168,8 @@ namespace Gentoo { DB::TablePatch t; t.src = "tmpEbuildUses"; t.dest = "gentoobrowse.ebuild_uses"; - t.pk = { "ebuildid", "use" }; - t.cols = { "ebuildid", "use", "defaultflag" }; + t.pk = {"ebuildid", "use"}; + t.cols = {"ebuildid", "use", "defaultflag"}; t.where = &ebuildIds; dbc->patchTable(&t); } @@ -167,15 +178,15 @@ namespace Gentoo { DB::TablePatch t; t.src = "tmpEbuildArchs"; t.dest = "gentoobrowse.ebuild_archs"; - t.pk = { "ebuildid", "arch" }; - t.cols = { "ebuildid", "arch" }; + t.pk = {"ebuildid", "arch"}; + t.cols = {"ebuildid", "arch"}; t.where = &ebuildIds; dbc->patchTable(&t); } } if (!packagesToPrune.empty()) { bool any = false; - for(const auto & catPkg : packagesToPrune) { + for (const auto & catPkg : packagesToPrune) { // Prune packages auto pp = sql::maintenance::packagePrune.modify(dbc); pp->bindParamS(0, catPkg.first); @@ -198,7 +209,8 @@ namespace Gentoo { } void - EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const U::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) + EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const U::EbuildCacheParser & ecp, int64_t ebuildId, + bool newest, int64_t packageId) { ebuildIds.entityIds.insert(ebuildId); // IUSE @@ -230,8 +242,8 @@ namespace Gentoo { U::SplitEbuildProps sep_homepage("packageId", packageId, "url", ecp.get("HOMEPAGE")); t.dest = "gentoobrowse.package_urls"; t.srcExpr = &sep_homepage; - t.pk = { "packageId", "url" }; - t.cols = { "packageId", "url" }; + t.pk = {"packageId", "url"}; + t.cols = {"packageId", "url"}; t.where = &pwf; dbc->patchTable(&t); // Description @@ -243,7 +255,8 @@ namespace Gentoo { } template<typename T> - const T & operator|=(const IceUtil::Optional<T> & a, const T & b) + const T & + operator|=(const IceUtil::Optional<T> & a, const T & b) { return a ? *a : b; } @@ -279,10 +292,9 @@ namespace Gentoo { m->bindParamS(2, packageName); m->bindParamS(3, ebuildVersion); m->execute(false); - packagesToPrune.insert({ categoryName, packageName }); + packagesToPrune.insert({categoryName, packageName}); } } } } FACTORY(Gentoo::Service::EbuildMetaProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index 89f2751..c198262 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -3,44 +3,46 @@ #include "abstractFileProcessor.h" #include "utils/ebuildCacheParser.h" -#include <portage-models.h> +#include "utils/entityWhereFilter.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> -#include "utils/entityWhereFilter.h" +#include <modifycommand.h> +#include <portage-models.h> namespace Gentoo { namespace Service { class EbuildMetaProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; - - EbuildMetaProcessor(); - - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; - - private: - void prepare(DB::Connection * dbc) override; - void apply(DB::Connection * dbc, ChangeSet &) override; - void tidy(DB::Connection * dbc) override; - - void perEbuildUpdates(DB::Connection * dbc, const Utils::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId); - void insertDeps(const std::vector<Gentoo::DependencyPtr> &); - - DB::ModifyCommandPtr depInsert; - DB::ModifyCommandPtr useInsert; - DB::ModifyCommandPtr archInsert; - Utils::EntityWhereFilter<int64_t> ebuildIds; - typedef std::pair<std::string, std::string> CategoryPackage; - typedef std::set<CategoryPackage> PackagesToPrune; - PackagesToPrune packagesToPrune; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; + + EbuildMetaProcessor(); + + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + + private: + void prepare(DB::Connection * dbc) override; + void apply(DB::Connection * dbc, ChangeSet &) override; + void tidy(DB::Connection * dbc) override; + + void perEbuildUpdates(DB::Connection * dbc, const Utils::EbuildCacheParser & ecp, int64_t ebuildId, + bool newest, int64_t packageId); + void insertDeps(const std::vector<Gentoo::DependencyPtr> &); + + DB::ModifyCommandPtr depInsert; + DB::ModifyCommandPtr useInsert; + DB::ModifyCommandPtr archInsert; + Utils::EntityWhereFilter<int64_t> ebuildIds; + typedef std::pair<std::string, std::string> CategoryPackage; + typedef std::set<CategoryPackage> PackagesToPrune; + PackagesToPrune packagesToPrune; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.cpp b/gentoobrowse-api/service/maintenance/masksProcessor.cpp index 9476f20..86c9c1f 100644 --- a/gentoobrowse-api/service/maintenance/masksProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/masksProcessor.cpp @@ -1,28 +1,38 @@ #include "masksProcessor.h" -#include <boost/algorithm/string/trim.hpp> +#include "sql/maintenance/masksEbuilds.sql.h" +#include "sql/maintenance/masksFixDates.sql.h" +#include "sql/maintenance/masksSets.sql.h" +#include "utils/dbUtils.h" #include <boost/algorithm/string/join.hpp> +#include <boost/algorithm/string/trim.hpp> +#include <fileUtils.h> +#include <glibmm/regex.h> +#include <mask.h> #include <modifycommand.h> #include <sqlWriter.h> #include <tablepatch.h> -#include "utils/dbUtils.h" -#include <glibmm/regex.h> -#include <fileUtils.h> -#include <mask.h> -#include "sql/maintenance/masksSets.sql.h" -#include "sql/maintenance/masksFixDates.sql.h" -#include "sql/maintenance/masksEbuilds.sql.h" namespace Gentoo { namespace Service { - unsigned char MasksProcessor::phase() const { return 2; } - unsigned char MasksProcessor::order() const { return 10; } - bool MasksProcessor::match(const PathParts & pp) const + unsigned char + MasksProcessor::phase() const + { + return 2; + } + unsigned char + MasksProcessor::order() const + { + return 10; + } + bool + MasksProcessor::match(const PathParts & pp) const { return (pp.size() == 2 && pp[0] == "profiles" && pp[1] == "package.mask"); } void - MasksProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + MasksProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } @@ -30,46 +40,48 @@ namespace Gentoo { void MasksProcessor::modified(DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) { - auto tempTable = Utils::Database::namedTemp(dbc, "tmp_masks", { - { "n", "int" }, - { "dateAdded", "date" }, - { "person", "text" }, - { "email", "text" }, - { "message", "text" }, - { "atomSpec", "text[]" } - }); + auto tempTable = Utils::Database::namedTemp(dbc, "tmp_masks", + {{"n", "int"}, {"dateAdded", "date"}, {"person", "text"}, {"email", "text"}, {"message", "text"}, + {"atomSpec", "text[]"}}); auto i = tempTable.second; AdHoc::FileUtils::MemMap f(path); class MaskInserter : public Portage::Utils::Masks { - public: - MaskInserter(DB::ModifyCommand * i) : i(i) { } + public: + MaskInserter(DB::ModifyCommand * i) : i(i) { } - protected: - void consume() const override - { - i->bindParamS(0, "{" + boost::algorithm::join(atoms, ",") + "}"); - i->bindParamS(1, date); - if (email) i->bindParamS(2, *email); else i->bindNull(2); - i->bindParamS(3, boost::algorithm::join(message, " ")); - i->bindParamI(4, n); - if (person) i->bindParamS(5, *person); else i->bindNull(5); - i->execute(); - } - DB::ModifyCommand * i; + protected: + void + consume() const override + { + i->bindParamS(0, "{" + boost::algorithm::join(atoms, ",") + "}"); + i->bindParamS(1, date); + if (email) + i->bindParamS(2, *email); + else + i->bindNull(2); + i->bindParamS(3, boost::algorithm::join(message, " ")); + i->bindParamI(4, n); + if (person) + i->bindParamS(5, *person); + else + i->bindNull(5); + i->execute(); + } + DB::ModifyCommand * i; }; - MaskInserter(tempTable.second.get()) - .extract((gchar *)f.data, f.getStat().st_size); + MaskInserter(tempTable.second.get()).extract((gchar *)f.data, f.getStat().st_size); // Dates are hand-typed and sometimes typos occur... ensure they're at // least within the range of Boost ptimes. - while (sql::maintenance::masksFixDates.modify(dbc)->execute()) ; + while (sql::maintenance::masksFixDates.modify(dbc)->execute()) + ; DB::TablePatch p; p.dest = "gentoobrowse.masksets"; DB::StaticSqlWriter srcExpr(sql::maintenance::masksSets.getSql()); p.srcExpr = &srcExpr; - p.pk = { "dateAdded", "n" }; - p.cols = { "dateAdded", "n", "person", "email", "message", "atomSpec" }; + p.pk = {"dateAdded", "n"}; + p.cols = {"dateAdded", "n", "person", "email", "message", "atomSpec"}; dbc->patchTable(&p); Utils::Database::drop(dbc, tempTable.first); @@ -82,7 +94,7 @@ namespace Gentoo { e.dest = "gentoobrowse.ebuild_masks"; DB::StaticSqlWriter srcExprE(sql::maintenance::masksEbuilds.getSql()); e.srcExpr = &srcExprE; - e.pk = { "ebuildId", "setNo" }; + e.pk = {"ebuildId", "setNo"}; e.cols = e.pk; dbc->patchTable(&e); } @@ -95,4 +107,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::MasksProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.h b/gentoobrowse-api/service/maintenance/masksProcessor.h index 31acfdc..fca6ec8 100644 --- a/gentoobrowse-api/service/maintenance/masksProcessor.h +++ b/gentoobrowse-api/service/maintenance/masksProcessor.h @@ -3,25 +3,26 @@ #include "abstractFileProcessor.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> +#include <modifycommand.h> namespace Gentoo { namespace Service { class MasksProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; - void phaseEnd(DB::Connection *, ChangeSet &) override; + void phaseEnd(DB::Connection *, ChangeSet &) override; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/newsProcessor.cpp b/gentoobrowse-api/service/maintenance/newsProcessor.cpp index e42d043..9f5cb55 100644 --- a/gentoobrowse-api/service/maintenance/newsProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/newsProcessor.cpp @@ -1,20 +1,30 @@ #include "newsProcessor.h" -#include <fileUtils.h> #include "news.h" -#include <modifycommand.h> -#include <slicer/slicer.h> +#include <boost/algorithm/string/predicate.hpp> #include <db/sqlInsertSerializer.h> #include <db/sqlUpdateSerializer.h> +#include <fileUtils.h> +#include <modifycommand.h> +#include <slicer/slicer.h> #include <sql/maintenance/newsDelete.sql.h> -#include <boost/algorithm/string/predicate.hpp> namespace Gentoo { namespace Service { - unsigned char NewsProcessor::phase() const { return 2; } - unsigned char NewsProcessor::order() const { return 10; } - bool NewsProcessor::match(const PathParts & pp) const + unsigned char + NewsProcessor::phase() const + { + return 2; + } + unsigned char + NewsProcessor::order() const { - return (pp.size() == 4 && pp[0] == "metadata" && pp[1] == "news" && boost::algorithm::ends_with(pp[3], ".txt")); + return 10; + } + bool + NewsProcessor::match(const PathParts & pp) const + { + return (pp.size() == 4 && pp[0] == "metadata" && pp[1] == "news" + && boost::algorithm::ends_with(pp[3], ".txt")); } void @@ -29,7 +39,7 @@ namespace Gentoo { importNews<Slicer::SqlUpdateSerializer>(dbc, path); } - template <typename Serializer> + template<typename Serializer> void NewsProcessor::importNews(DB::Connection * dbc, const std::filesystem::path & path) { @@ -49,4 +59,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::NewsProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/newsProcessor.h b/gentoobrowse-api/service/maintenance/newsProcessor.h index 024da5d..c51e1f8 100644 --- a/gentoobrowse-api/service/maintenance/newsProcessor.h +++ b/gentoobrowse-api/service/maintenance/newsProcessor.h @@ -9,21 +9,22 @@ namespace Gentoo { namespace Service { class NewsProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; - private: - template <typename Serializer> - static void importNews(DB::Connection * dbc, const std::filesystem::path & path); + private: + template<typename Serializer> + static void importNews(DB::Connection * dbc, const std::filesystem::path & path); }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp index 9fe0ca3..df3e2da 100644 --- a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp @@ -1,9 +1,9 @@ #include "packageMetaProcessor.h" +#include "utils/dbUtils.h" +#include "utils/xmlUtils.h" +#include <fileUtils.h> #include <modifycommand.h> #include <optionalUtils.h> -#include <fileUtils.h> -#include "utils/xmlUtils.h" -#include "utils/dbUtils.h" #include <sql/maintenance/packageMetaUpdate.sql.h> namespace U = Gentoo::Utils; @@ -12,28 +12,38 @@ using namespace AdHoc::FileUtils; namespace Gentoo { namespace Service { - unsigned char PackageMetaProcessor::phase() const { return 2; } - unsigned char PackageMetaProcessor::order() const { return 3; } - bool PackageMetaProcessor::match(const PathParts & pp) const + unsigned char + PackageMetaProcessor::phase() const + { + return 2; + } + unsigned char + PackageMetaProcessor::order() const + { + return 3; + } + bool + PackageMetaProcessor::match(const PathParts & pp) const { return (pp.size() == 3 && pp[2] == "metadata.xml"); } - void - PackageMetaProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + PackageMetaProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } void - PackageMetaProcessor::modified(DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) + PackageMetaProcessor::modified( + DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) { auto m = sql::maintenance::packageMetaUpdate.modify(dbc); U::XmlDoc md(path); m->bindParamS(0, - md.getXPathValue("/pkgmetadata/longdescription[@lang='en']/text()") / - md.getXPathValue("/pkgmetadata/longdescription[1]/text()")); + md.getXPathValue("/pkgmetadata/longdescription[@lang='en']/text()") + / md.getXPathValue("/pkgmetadata/longdescription[1]/text()")); m->bindParamS(1, md.getXPathValue("/pkgmetadata/herd/text()")); m->bindParamS(2, fn[0]); m->bindParamS(3, fn[1]); @@ -53,4 +63,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::PackageMetaProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.h b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h index 1b63a4a..2dfda96 100644 --- a/gentoobrowse-api/service/maintenance/packageMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h @@ -8,17 +8,18 @@ namespace Gentoo { namespace Service { class PackageMetaProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp index f5b0bd5..5899a46 100644 --- a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp @@ -1,108 +1,119 @@ #include "updatesProcessor.h" -#include <modifycommand.h> -#include <selectcommandUtil.impl.h> -#include <tablepatch.h> -#include <fileUtils.h> #include "utils/dbUtils.h" #include "utils/entityWhereFilter.h" -#include <glibmm/regex.h> +#include <boost/algorithm/string/join.hpp> +#include <boost/algorithm/string/predicate.hpp> +#include <fileUtils.h> #include <fstream> +#include <glibmm/regex.h> +#include <modifycommand.h> +#include <selectcommandUtil.impl.h> #include <sql/maintenance/categoryInsert.sql.h> #include <sql/maintenance/packageInsert.sql.h> #include <sql/maintenance/updatesMoveUserPackages.sql.h> #include <sql/portage/findPackage.sql.h> -#include <boost/algorithm/string/predicate.hpp> -#include <boost/algorithm/string/join.hpp> +#include <tablepatch.h> using namespace AdHoc::FileUtils; -static Glib::RefPtr<Glib::Regex> move = Glib::Regex::create( - R"R(^move ([^/]+)/([^ ]+) ([^/]+)/(.+)$)R", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr<Glib::Regex> move + = Glib::Regex::create(R"R(^move ([^/]+)/([^ ]+) ([^/]+)/(.+)$)R", Glib::RegexCompileFlags::REGEX_MULTILINE); namespace Gentoo { namespace Service { - unsigned char UpdatesProcessor::phase() const { return 1; } - unsigned char UpdatesProcessor::order() const { return 1; } - bool UpdatesProcessor::match(const PathParts & pp) const + unsigned char + UpdatesProcessor::phase() const + { + return 1; + } + unsigned char + UpdatesProcessor::order() const + { + return 1; + } + bool + UpdatesProcessor::match(const PathParts & pp) const { return (pp.size() == 3 && pp[0] == "profiles" && pp[1] == "updates" && pp[2].substr(1, 4) == "Q-20"); } class UpdatesPatch : public DB::TablePatch, public DB::SqlWriter { - public: - UpdatesPatch(DB::Connection * db) : - categoryInsert(sql::maintenance::categoryInsert.modify(db)), - packageInsert(sql::maintenance::packageInsert.modify(db)), - findPackage(sql::portage::findPackage.select(db)), - updatesMoveUserPackages(sql::maintenance::updatesMoveUserPackages.modify(db)), - changes(nullptr), - updatePacks("updatePack") - { - this->src = Utils::Database::emptyClone(db, "gentoobrowse.updates"); - this->dest = "gentoobrowse.updates"; - this->pk = { "updatePack", "catfrom", "namefrom" }; - this->cols = { "updatePack", "catfrom", "namefrom", "catto", "nameto" }; - this->where = &updatePacks; - this->order = this; - this->beforeInsert = std::bind(&UpdatesPatch::move, this, std::placeholders::_1); - drop = db->modify("DROP TABLE " + this->src); - } - - ~UpdatesPatch() - { - if (!std::uncaught_exceptions()) { - drop->execute(); - } - } + public: + UpdatesPatch(DB::Connection * db) : + categoryInsert(sql::maintenance::categoryInsert.modify(db)), + packageInsert(sql::maintenance::packageInsert.modify(db)), + findPackage(sql::portage::findPackage.select(db)), + updatesMoveUserPackages(sql::maintenance::updatesMoveUserPackages.modify(db)), changes(nullptr), + updatePacks("updatePack") + { + this->src = Utils::Database::emptyClone(db, "gentoobrowse.updates"); + this->dest = "gentoobrowse.updates"; + this->pk = {"updatePack", "catfrom", "namefrom"}; + this->cols = {"updatePack", "catfrom", "namefrom", "catto", "nameto"}; + this->where = &updatePacks; + this->order = this; + this->beforeInsert = std::bind(&UpdatesPatch::move, this, std::placeholders::_1); + drop = db->modify("DROP TABLE " + this->src); + } - void writeSql(AdHoc::Buffer & sql) override - { - sql.append("SPLIT_PART(b.updatePack, '-', 2)::INT, SUBSTR(b.updatePack, 1, 1)::INT"); + ~UpdatesPatch() + { + if (!std::uncaught_exceptions()) { + drop->execute(); } + } - DB::ModifyCommandPtr drop; - DB::ModifyCommandPtr categoryInsert; - DB::ModifyCommandPtr packageInsert; - DB::SelectCommandPtr findPackage; - DB::ModifyCommandPtr updatesMoveUserPackages; - ChangeSet * changes; - Utils::EntityWhereFilter<std::string> updatePacks; + void + writeSql(AdHoc::Buffer & sql) override + { + sql.append("SPLIT_PART(b.updatePack, '-', 2)::INT, SUBSTR(b.updatePack, 1, 1)::INT"); + } - void - move(DB::SelectCommandPtr s) - { - s->forEachRow<std::string, std::string, std::string, std::string, std::string>([this](auto catfrom, auto catto, auto namefrom, auto nameto, auto) { - if (this->exists(catfrom, namefrom) && !this->exists(catto, nameto)) { // Does target already exist? - // Create category - categoryInsert->bindParamS(0, catto); - categoryInsert->bindParamS(1, catto); - categoryInsert->execute(); - // Create package - packageInsert->bindParamS(0, nameto); - packageInsert->bindParamS(1, "Created by package move"); - packageInsert->bindParamS(2, nameto); - packageInsert->bindParamS(3, catto); - packageInsert->execute(); - } - updatesMoveUserPackages->bindParamS(0, catfrom); - updatesMoveUserPackages->bindParamS(1, namefrom); - updatesMoveUserPackages->bindParamS(2, catto); - updatesMoveUserPackages->bindParamS(3, nameto); - updatesMoveUserPackages->execute(); - }); - } + DB::ModifyCommandPtr drop; + DB::ModifyCommandPtr categoryInsert; + DB::ModifyCommandPtr packageInsert; + DB::SelectCommandPtr findPackage; + DB::ModifyCommandPtr updatesMoveUserPackages; + ChangeSet * changes; + Utils::EntityWhereFilter<std::string> updatePacks; + + void + move(DB::SelectCommandPtr s) + { + s->forEachRow<std::string, std::string, std::string, std::string, std::string>( + [this](auto catfrom, auto catto, auto namefrom, auto nameto, auto) { + if (this->exists(catfrom, namefrom) + && !this->exists(catto, nameto)) { // Does target already exist? + // Create category + categoryInsert->bindParamS(0, catto); + categoryInsert->bindParamS(1, catto); + categoryInsert->execute(); + // Create package + packageInsert->bindParamS(0, nameto); + packageInsert->bindParamS(1, "Created by package move"); + packageInsert->bindParamS(2, nameto); + packageInsert->bindParamS(3, catto); + packageInsert->execute(); + } + updatesMoveUserPackages->bindParamS(0, catfrom); + updatesMoveUserPackages->bindParamS(1, namefrom); + updatesMoveUserPackages->bindParamS(2, catto); + updatesMoveUserPackages->bindParamS(3, nameto); + updatesMoveUserPackages->execute(); + }); + } - bool - exists(const std::string & cat, const std::string & pkg) - { - bool found = false; - findPackage->bindParamS(0, cat); - findPackage->bindParamS(1, pkg); - while (findPackage->fetch()) { - found = true; - } - return found; + bool + exists(const std::string & cat, const std::string & pkg) + { + bool found = false; + findPackage->bindParamS(0, cat); + findPackage->bindParamS(1, pkg); + while (findPackage->fetch()) { + found = true; } + return found; + } }; void @@ -127,13 +138,15 @@ namespace Gentoo { } void - UpdatesProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + UpdatesProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } void - UpdatesProcessor::modified(DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) + UpdatesProcessor::modified( + DB::Connection * dbc, int64_t, const StringList & fn, const std::filesystem::path & path) { AdHoc::FileUtils::MemMap u(path); Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size)); @@ -159,4 +172,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::UpdatesProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/updatesProcessor.h b/gentoobrowse-api/service/maintenance/updatesProcessor.h index 06dc0f2..fa7a390 100644 --- a/gentoobrowse-api/service/maintenance/updatesProcessor.h +++ b/gentoobrowse-api/service/maintenance/updatesProcessor.h @@ -3,32 +3,32 @@ #include "abstractFileProcessor.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> +#include <modifycommand.h> namespace Gentoo { namespace Service { class UpdatesPatch; class UpdatesProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; - - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; - - void prepare(DB::Connection * dbc) override; - void apply(DB::Connection * dbc, ChangeSet &) override; - void tidy(DB::Connection * dbc) override; - - private: - UpdatesPatch * up; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; + + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + + void prepare(DB::Connection * dbc) override; + void apply(DB::Connection * dbc, ChangeSet &) override; + void tidy(DB::Connection * dbc) override; + + private: + UpdatesPatch * up; }; } } #endif - - diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp index 4ce8d21..2ab2632 100644 --- a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp @@ -1,37 +1,49 @@ #include "useGlobalProcessor.h" -#include <modifycommand.h> -#include <tablepatch.h> -#include <fileUtils.h> #include "utils/dbUtils.h" +#include <fileUtils.h> #include <glibmm/regex.h> +#include <modifycommand.h> +#include <tablepatch.h> using namespace AdHoc::FileUtils; -static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr<Glib::Regex> useDesc + = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); namespace Gentoo { namespace Service { - unsigned char UseGlobalProcessor::phase() const { return 2; } - unsigned char UseGlobalProcessor::order() const { return 10; } - bool UseGlobalProcessor::match(const PathParts & pp) const + unsigned char + UseGlobalProcessor::phase() const + { + return 2; + } + unsigned char + UseGlobalProcessor::order() const + { + return 10; + } + bool + UseGlobalProcessor::match(const PathParts & pp) const { return (pp.size() == 2 && pp[0] == "profiles" && pp[1] == "use.desc"); } void - UseGlobalProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + UseGlobalProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } void - UseGlobalProcessor::modified(DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) + UseGlobalProcessor::modified( + DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) { DB::TablePatch p; p.dest = "gentoobrowse.use_global"; p.src = Utils::Database::emptyClone(dbc, p.dest); - p.pk = { "use" }; - p.cols = { "use", "description" }; + p.pk = {"use"}; + p.cols = {"use", "description"}; AdHoc::FileUtils::MemMap u(path); Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size)); @@ -55,4 +67,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::UseGlobalProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.h b/gentoobrowse-api/service/maintenance/useGlobalProcessor.h index c052873..a7fdc78 100644 --- a/gentoobrowse-api/service/maintenance/useGlobalProcessor.h +++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.h @@ -3,23 +3,24 @@ #include "abstractFileProcessor.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> +#include <modifycommand.h> namespace Gentoo { namespace Service { class UseGlobalProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp index 93ab2ad..c213c26 100644 --- a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp @@ -1,47 +1,60 @@ #include "useGroupProcessor.h" -#include <modifycommand.h> -#include <selectcommandUtil.impl.h> -#include <tablepatch.h> -#include <fileUtils.h> -#include "utils/dbUtils.h" -#include "utils/entityWhereFilter.h" -#include <glibmm/regex.h> #include "sql/maintenance/useGroupsDelete.sql.h" -#include "sql/maintenance/useGroupsInsert.sql.h" #include "sql/maintenance/useGroupsGetId.sql.h" +#include "sql/maintenance/useGroupsInsert.sql.h" +#include "utils/dbUtils.h" +#include "utils/entityWhereFilter.h" #include <boost/algorithm/string/predicate.hpp> +#include <fileUtils.h> +#include <glibmm/regex.h> +#include <modifycommand.h> +#include <selectcommandUtil.impl.h> +#include <tablepatch.h> namespace U = Gentoo::Utils; -static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr<Glib::Regex> useDesc + = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); namespace Gentoo { namespace Service { - unsigned char UseGroupProcessor::phase() const { return 2; } - unsigned char UseGroupProcessor::order() const { return 10; } - bool UseGroupProcessor::match(const PathParts & pp) const + unsigned char + UseGroupProcessor::phase() const { - return (pp.size() == 3 && pp[0] == "profiles" && pp[1] == "desc" && boost::algorithm::ends_with(pp[2], ".desc")); + return 2; + } + unsigned char + UseGroupProcessor::order() const + { + return 10; + } + bool + UseGroupProcessor::match(const PathParts & pp) const + { + return (pp.size() == 3 && pp[0] == "profiles" && pp[1] == "desc" + && boost::algorithm::ends_with(pp[2], ".desc")); } void - UseGroupProcessor::created(DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) + UseGroupProcessor::created( + DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) { auto m = sql::maintenance::useGroupsInsert.select(dbc); m->bindParamS(0, path.stem().string()); m->forEachRow<int64_t>([this, dbc, &path](auto useGroupId) { - this->mergeContent(dbc, path, useGroupId); - }); + this->mergeContent(dbc, path, useGroupId); + }); } void - UseGroupProcessor::modified(DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) + UseGroupProcessor::modified( + DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) { auto m = sql::maintenance::useGroupsGetId.select(dbc); m->bindParamS(0, path.stem().string()); m->forEachRow<int64_t>([this, dbc, &path](auto useGroupId) { - this->mergeContent(dbc, path, useGroupId); - }); + this->mergeContent(dbc, path, useGroupId); + }); } void @@ -51,8 +64,8 @@ namespace Gentoo { p.dest = "gentoobrowse.use_group"; U::EntityWhereFilter<int64_t> gwf("useGroupId", useGroupId); p.src = Utils::Database::emptyClone(dbc, "gentoobrowse.use_group"); - p.pk = { "useGroupId", "use" }; - p.cols = { "useGroupId", "use", "description" }; + p.pk = {"useGroupId", "use"}; + p.cols = {"useGroupId", "use", "description"}; p.where = &gwf; AdHoc::FileUtils::MemMap u(path); @@ -85,4 +98,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::UseGroupProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/useGroupProcessor.h b/gentoobrowse-api/service/maintenance/useGroupProcessor.h index 758af3a..29b1bb1 100644 --- a/gentoobrowse-api/service/maintenance/useGroupProcessor.h +++ b/gentoobrowse-api/service/maintenance/useGroupProcessor.h @@ -3,26 +3,27 @@ #include "abstractFileProcessor.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> +#include <modifycommand.h> namespace Gentoo { namespace Service { class UseGroupProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; - private: - void mergeContent(DB::Connection *, const std::filesystem::path &, int64_t id); + private: + void mergeContent(DB::Connection *, const std::filesystem::path &, int64_t id); }; } } #endif - diff --git a/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp index bce8c2a..5495b46 100644 --- a/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp @@ -1,46 +1,54 @@ #include "useLocalProcessor.h" +#include "sql/maintenance/useLocalMap.sql.h" +#include "utils/dbUtils.h" +#include <fileUtils.h> +#include <glibmm/regex.h> #include <modifycommand.h> #include <sqlWriter.h> #include <tablepatch.h> -#include <fileUtils.h> -#include "utils/dbUtils.h" -#include <glibmm/regex.h> -#include "sql/maintenance/useLocalMap.sql.h" using namespace AdHoc::FileUtils; -static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^/]*)/([^:]+):([^ ]+)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create( + "^([^#\\s][^/]*)/([^:]+):([^ ]+)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); namespace Gentoo { namespace Service { - unsigned char UseLocalProcessor::phase() const { return 2; } - unsigned char UseLocalProcessor::order() const { return 10; } - bool UseLocalProcessor::match(const PathParts & pp) const + unsigned char + UseLocalProcessor::phase() const + { + return 2; + } + unsigned char + UseLocalProcessor::order() const + { + return 10; + } + bool + UseLocalProcessor::match(const PathParts & pp) const { return (pp.size() == 2 && pp[0] == "profiles" && pp[1] == "use.local.desc"); } void - UseLocalProcessor::created(DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) + UseLocalProcessor::created( + DB::Connection * dbc, int64_t r, const StringList & fn, const std::filesystem::path & path) { modified(dbc, r, fn, path); } void - UseLocalProcessor::modified(DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) + UseLocalProcessor::modified( + DB::Connection * dbc, int64_t, const StringList &, const std::filesystem::path & path) { DB::TablePatch p; - auto tempTable = Utils::Database::namedTemp(dbc, "tmp_uselocalraw", { - { "category", "text" }, - { "package", "text" }, - { "use", "text" }, - { "description", "text" } - }); + auto tempTable = Utils::Database::namedTemp(dbc, "tmp_uselocalraw", + {{"category", "text"}, {"package", "text"}, {"use", "text"}, {"description", "text"}}); p.dest = "gentoobrowse.use_local"; DB::StaticSqlWriter srcExpr(sql::maintenance::useLocalMap.getSql()); p.srcExpr = &srcExpr; - p.pk = { "packageId", "use" }; - p.cols = { "packageId", "use", "description" }; + p.pk = {"packageId", "use"}; + p.cols = {"packageId", "use", "description"}; AdHoc::FileUtils::MemMap u(path); Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size)); @@ -66,4 +74,3 @@ namespace Gentoo { } } FACTORY(Gentoo::Service::UseLocalProcessor, Gentoo::Service::FileProcessorFactory); - diff --git a/gentoobrowse-api/service/maintenance/useLocalProcessor.h b/gentoobrowse-api/service/maintenance/useLocalProcessor.h index 4186a33..b2077bc 100644 --- a/gentoobrowse-api/service/maintenance/useLocalProcessor.h +++ b/gentoobrowse-api/service/maintenance/useLocalProcessor.h @@ -3,23 +3,24 @@ #include "abstractFileProcessor.h" #include <connection.h> -#include <modifycommand.h> #include <filesystem> +#include <modifycommand.h> namespace Gentoo { namespace Service { class UseLocalProcessor : public AbstractFileProcessor { - public: - unsigned char phase() const override; - unsigned char order() const override; - bool match(const PathParts & pp) const override; + public: + unsigned char phase() const override; + unsigned char order() const override; + bool match(const PathParts & pp) const override; - void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, const std::filesystem::path & path) override; - void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; + void created(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void modified(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn, + const std::filesystem::path & path) override; + void deleted(DB::Connection * dbc, int64_t repoid, const Gentoo::StringList & fn) override; }; } } #endif - diff --git a/gentoobrowse-api/service/maintenanceBugs.cpp b/gentoobrowse-api/service/maintenanceBugs.cpp index aee9003..ededc29 100644 --- a/gentoobrowse-api/service/maintenanceBugs.cpp +++ b/gentoobrowse-api/service/maintenanceBugs.cpp @@ -1,16 +1,16 @@ #include "maintenanceimpl.h" -#include <stack> #include <boost/lexical_cast.hpp> -#include <selectcommandUtil.impl.h> -#include <tablepatch.h> +#include <compileTimeFormatter.h> #include <curlStream.h> -#include <libxml++/parsers/saxparser.h> -#include <lexer.h> #include <lexer-regex.h> -#include <utils/dbUtils.h> -#include <compileTimeFormatter.h> +#include <lexer.h> +#include <libxml++/parsers/saxparser.h> #include <logger.h> #include <nagios.h> +#include <selectcommandUtil.impl.h> +#include <stack> +#include <tablepatch.h> +#include <utils/dbUtils.h> namespace Gentoo { namespace Service { @@ -18,51 +18,53 @@ namespace Gentoo { R"R(Bug:(\d+) - "" status:(\w*) resolution:(\w*) severity:(\w*).*)R", G_REGEX_OPTIMIZE); class BugListParser : public xmlpp::SaxParser, AdHoc::Lexer { - public: - BugListParser(DB::ModifyCommandPtr i) : - ins(i) - { - rules.push_back({ { InitialState }, bugLink, [this](auto es) { - ins->bindParamI(0, boost::lexical_cast<int64_t>(*es->pattern()->match(1))); - ins->bindParamS(2, *es->pattern()->match(2)); - ins->bindParamS(1, *es->pattern()->match(4)); - }}); - } + public: + BugListParser(DB::ModifyCommandPtr i) : ins(i) + { + rules.push_back({{InitialState}, bugLink, [this](auto es) { + ins->bindParamI(0, boost::lexical_cast<int64_t>(*es->pattern()->match(1))); + ins->bindParamS(2, *es->pattern()->match(2)); + ins->bindParamS(1, *es->pattern()->match(4)); + }}); + } - protected: - void on_start_element(const Glib::ustring & e, const xmlpp::SaxParser::AttributeList &) override - { - stk.push(e); - } + protected: + void + on_start_element(const Glib::ustring & e, const xmlpp::SaxParser::AttributeList &) override + { + stk.push(e); + } - void on_characters(const Glib::ustring & t) override - { - if (stk.top() == "a") { - attributes += t; - } - else if (stk.top() == "em") { - summary += t; - } + void + on_characters(const Glib::ustring & t) override + { + if (stk.top() == "a") { + attributes += t; + } + else if (stk.top() == "em") { + summary += t; } + } - void on_end_element(const Glib::ustring & e) override - { - stk.pop(); - if (e == "li") { - extract(attributes.c_str(), attributes.length()); - ins->bindParamS(3, summary); - ins->execute(); - attributes.clear(); - summary.clear(); - } + void + on_end_element(const Glib::ustring & e) override + { + stk.pop(); + if (e == "li") { + extract(attributes.c_str(), attributes.length()); + ins->bindParamS(3, summary); + ins->execute(); + attributes.clear(); + summary.clear(); } + } - private: - DB::ModifyCommandPtr ins; - std::stack<Glib::ustring> stk; + private: + DB::ModifyCommandPtr ins; + std::stack<Glib::ustring> stk; - Glib::ustring attributes; - Glib::ustring summary; + Glib::ustring attributes; + Glib::ustring summary; }; AdHocFormatter(UpdatingBugs, "Refreshing bug list from %?"); @@ -81,16 +83,14 @@ namespace Gentoo { auto dbc = db->get(); DB::TransactionScope tx(*dbc.get()); DB::TablePatch tp; - tp.pk = { "bugId" }; - tp.cols = { "bugId", "severity", "status", "summary" }; + tp.pk = {"bugId"}; + tp.cols = {"bugId", "severity", "status", "summary"}; tp.dest = "gentoobrowse.bugs"; tp.src = Utils::Database::emptyClone(dbc.get(), "gentoobrowse.bugs"); auto ins = Utils::Database::tablePatchInserter(dbc.get(), tp); BugListParser blp(ins); - for(const auto & bl : { - "buglist-CONFIRMED.html", - "buglist-UNCONFIRMED.html", - "buglist-IN_PROGRESS.html" }) { + for (const auto & bl : + {"buglist-CONFIRMED.html", "buglist-UNCONFIRMED.html", "buglist-IN_PROGRESS.html"}) { log->messagectf<UpdatingBugUrl>(IceTray::Logging::LogLevel::DEBUG, bl); AdHoc::Net::CurlStreamSource css(root / bl); css.setopt(CURLOPT_ENCODING, "deflate, gzip"); @@ -100,7 +100,8 @@ namespace Gentoo { } auto result = dbc->patchTable(&tp); Utils::Database::drop(dbc.get(), tp.src); - log->messagectf<UpdatingBugsResult>(IceTray::Logging::LogLevel::INFO, result.inserts, result.updates, result.deletes); + log->messagectf<UpdatingBugsResult>( + IceTray::Logging::LogLevel::INFO, result.inserts, result.updates, result.deletes); AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::OK, UpdatingBugsResult::get(result.inserts, result.updates, result.deletes)); } @@ -111,4 +112,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/maintenanceCommon.cpp b/gentoobrowse-api/service/maintenanceCommon.cpp index 7bcc195..eb11648 100644 --- a/gentoobrowse-api/service/maintenanceCommon.cpp +++ b/gentoobrowse-api/service/maintenanceCommon.cpp @@ -1,60 +1,60 @@ #include "maintenanceimpl.h" -#include <Ice/ObjectAdapter.h> +#include "sql/maintenance/getNotificationEbuildLists.sql.h" #include <Ice/Communicator.h> +#include <Ice/ObjectAdapter.h> +#include <icecube.h> #include <notifications.h> #include <portage.h> -#include <users.h> #include <safeMapFind.h> -#include <icecube.h> -#include "sql/maintenance/getNotificationEbuildLists.sql.h" +#include <users.h> namespace Gentoo { namespace Service { class BaseScheduledTask : public IceUtil::TimerTask { - public: - BaseScheduledTask(Ice::CommunicatorPtr i) : ic(i) - { - } + public: + BaseScheduledTask(Ice::CommunicatorPtr i) : ic(i) { } - private: - Ice::CommunicatorPtr ic; + private: + Ice::CommunicatorPtr ic; }; class AutoUpdatePackages : public BaseScheduledTask { - public: - AutoUpdatePackages(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { } - - void runTimerTask() override { - auto m = IceTray::Cube::get<Maintenance>(); - auto rb = m->refreshBugsAsync(); - m->updateRepositories(); - m->refreshPackageTree(); - m->sendNotifications(); - rb.get(); - } + public: + AutoUpdatePackages(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { } + + void + runTimerTask() override + { + auto m = IceTray::Cube::get<Maintenance>(); + auto rb = m->refreshBugsAsync(); + m->updateRepositories(); + m->refreshPackageTree(); + m->sendNotifications(); + rb.get(); + } }; class UserMaintenance : public BaseScheduledTask { - public: - UserMaintenance(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { } - - void runTimerTask() override { - auto u = IceTray::Cube::get<Users>(); - u->prune(); - } + public: + UserMaintenance(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { } + + void + runTimerTask() override + { + auto u = IceTray::Cube::get<Users>(); + u->prune(); + } }; - Maintenance::Maintenance(const DB::ConnectionPoolPtr & d, const Ice::CommunicatorPtr & ic, const Ice::PropertiesPtr & p) : + Maintenance::Maintenance( + const DB::ConnectionPoolPtr & d, const Ice::CommunicatorPtr & ic, const Ice::PropertiesPtr & p) : Maintenance::Maintenance(d) { addTask<AutoUpdatePackages>(ic, p, "SyncTime"); addTask<UserMaintenance>(ic, p, "UserMaintenanceTime"); } - Maintenance::Maintenance(const DB::ConnectionPoolPtr & d) : - IceTray::AbstractDatabaseClient(d) - { - } + Maintenance::Maintenance(const DB::ConnectionPoolPtr & d) : IceTray::AbstractDatabaseClient(d) { } Maintenance::~Maintenance() { @@ -90,22 +90,25 @@ namespace Gentoo { UserNews un; auto t = fetch<NewsContentTriggers>(sql::maintenance::getNotificationEbuildLists); - std::transform(t.begin(), t.end(), std::inserter(un, un.end()), [&categories,&portage](const NewsContentTriggers::value_type & t) { - NewsContent nc; - std::copy_if(categories.begin(), categories.end(), std::back_inserter(nc.categories), [&t](const Gentoo::CategoryPtr & c) { - return AdHoc::containerContains(t.categoryids, c->categoryid); - }); - for (auto pid : t.packageids) { - auto par = portage->getPackageAsync(pid); - auto vsar = portage->getPackageVersionsAsync(pid); - nc.packages.push_back(par.get()); - auto vs = vsar.get(); - std::copy_if(vs.begin(), vs.end(), std::back_inserter(nc.ebuilds), [&t](const Gentoo::EbuildPtr & v) { - return AdHoc::containerContains(t.ebuildids, v->ebuildid); + std::transform(t.begin(), t.end(), std::inserter(un, un.end()), + [&categories, &portage](const NewsContentTriggers::value_type & t) { + NewsContent nc; + std::copy_if(categories.begin(), categories.end(), std::back_inserter(nc.categories), + [&t](const Gentoo::CategoryPtr & c) { + return AdHoc::containerContains(t.categoryids, c->categoryid); + }); + for (auto pid : t.packageids) { + auto par = portage->getPackageAsync(pid); + auto vsar = portage->getPackageVersionsAsync(pid); + nc.packages.push_back(par.get()); + auto vs = vsar.get(); + std::copy_if(vs.begin(), vs.end(), std::back_inserter(nc.ebuilds), + [&t](const Gentoo::EbuildPtr & v) { + return AdHoc::containerContains(t.ebuildids, v->ebuildid); + }); + } + return UserNews::value_type(t.userid, nc); }); - } - return UserNews::value_type(t.userid, nc); - }); return un; } @@ -126,4 +129,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp index 2a72fe6..503a1cf 100644 --- a/gentoobrowse-api/service/maintenanceGitOperations.cpp +++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp @@ -1,21 +1,21 @@ +#include "converters.impl.h" #include "maintenanceimpl.h" -#include <Ice/ObjectAdapter.h> +#include "utils/git.h" #include <Ice/Communicator.h> +#include <Ice/ObjectAdapter.h> #include <boost/lexical_cast.hpp> -#include <selectcommandUtil.impl.h> -#include <utils/dbUtils.h> +#include <compileTimeFormatter.h> #include <git2.h> +#include <logger.h> +#include <nagios.h> +#include <portage-models.h> +#include <selectcommandUtil.impl.h> #include <sql/maintenance/changeLogInsert.sql.h> -#include <sql/maintenance/reposToUpdate.sql.h> -#include <sql/maintenance/reposToGitRefresh.sql.h> #include <sql/maintenance/repoSetLastCommit.sql.h> -#include <portage-models.h> -#include "utils/git.h" -#include "converters.impl.h" -#include <compileTimeFormatter.h> +#include <sql/maintenance/reposToGitRefresh.sql.h> +#include <sql/maintenance/reposToUpdate.sql.h> #include <systemd/sd-daemon.h> -#include <logger.h> -#include <nagios.h> +#include <utils/dbUtils.h> namespace Gentoo { namespace Service { @@ -24,8 +24,7 @@ namespace Gentoo { typedef std::set<std::string> StringSet; - static - int + static int onFile(const git_diff_delta * delta, void * fileset) { static_cast<StringSet *>(fileset)->insert(delta->old_file.path); @@ -34,8 +33,7 @@ namespace Gentoo { } template<typename T> - static - int + static int onFile(const git_diff_delta * delta, T, void * fileset) { return onFile(delta, fileset); @@ -43,9 +41,9 @@ namespace Gentoo { AdHocFormatter(UpdatingChangeLog, "Updating change log for repository %? with range %?...%?"); AdHocFormatter(UpdatedChangeLog, "Updated change log for repository %?, added %? new entries"); - static - void - writeChangeLog(DB::Connection * db, int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, const git_oid & headCommitOid) + static void + writeChangeLog(DB::Connection * db, int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, + const git_oid & headCommitOid) { auto log = LOGMANAGER()->getLogger(__FUNCTION__); log->messagectf<UpdatingChangeLog>(IceTray::Logging::LogLevel::INFO, repoId, lastCommitOid, headCommitOid); @@ -67,17 +65,19 @@ namespace Gentoo { auto currentTree = gitSafeGet(git_commit_tree, git_tree_free, commit.get()); // Collect all files change in commit from all parents - std::unique_ptr<git_tree, void(*)(git_tree*)> parentTree(nullptr, git_tree_free); + std::unique_ptr<git_tree, void (*)(git_tree *)> parentTree(nullptr, git_tree_free); if (git_commit_parentcount(commit.get()) > 0) { auto parentCommit = gitSafeGet(git_commit_parent, git_commit_free, commit.get(), 0); // Get parent tree parentTree = gitSafeGet(git_commit_tree, git_tree_free, parentCommit.get()); } // Get tree to tree diff - auto diff = gitSafeGet(git_diff_tree_to_tree, git_diff_free, repo, currentTree.get(), parentTree.get(), nullptr); + auto diff = gitSafeGet( + git_diff_tree_to_tree, git_diff_free, repo, currentTree.get(), parentTree.get(), nullptr); // Compare trees StringSet fs; - gitSafe(git_diff_foreach, diff.get(), onFile<float>, onFile<const git_diff_binary *>, nullptr, nullptr, &fs); + gitSafe(git_diff_foreach, diff.get(), onFile<float>, onFile<const git_diff_binary *>, nullptr, nullptr, + &fs); // Insert commit into DB auto sig = git_commit_author(commit.get()); @@ -101,20 +101,17 @@ namespace Gentoo { } } - static - int + static int insertFileChange(const git_diff_delta * delta, void * ptr) { auto cs = static_cast<ChangeSet *>(ptr); switch (delta->status) { case GIT_DELTA_ADDED: case GIT_DELTA_MODIFIED: - case GIT_DELTA_DELETED: - { - std::filesystem::path path(delta->new_file.path); - cs->insert({ path, { { path.begin(), path.end() }, delta->status }}); - } - break; + case GIT_DELTA_DELETED: { + std::filesystem::path path(delta->new_file.path); + cs->insert({path, {{path.begin(), path.end()}, delta->status}}); + } break; default: throw GitError("Insert Git file changes", 0, 0, "Unexpected change status."); } @@ -122,16 +119,14 @@ namespace Gentoo { } template<typename T> - static - int + static int insertFileChangeT(const git_diff_delta * delta, T, void * ptr) { return insertFileChange(delta, ptr); } - static - ChangeSet - writeChangesToFileList(int64_t repoId, git_repository * repo, const git_oid & last, const git_oid & head); + static ChangeSet writeChangesToFileList( + int64_t repoId, git_repository * repo, const git_oid & last, const git_oid & head); ChangeSet refreshRepository(DB::Connection * db, Ice::PropertiesPtr properties, const Repository & repository) @@ -139,9 +134,8 @@ namespace Gentoo { auto targetRef = properties->getProperty("GentooBrowseAPI.RefreshTarget." + repository.name); auto repo = gitSafeGet(git_repository_open, git_repository_free, repository.path.c_str()); auto lastCommitOid = gitSafeGet(git_oid_fromstr, repository.lastcommit.c_str()); - auto headCommitOid = targetRef.empty() ? - gitSafeGet(git_reference_name_to_id, repo.get(), "HEAD") : - gitSafeGet(git_oid_fromstr, targetRef.c_str()); + auto headCommitOid = targetRef.empty() ? gitSafeGet(git_reference_name_to_id, repo.get(), "HEAD") + : gitSafeGet(git_oid_fromstr, targetRef.c_str()); auto updateLastCommit = sql::maintenance::repoSetLastCommit.modify(db); updateLastCommit->bindParamS(0, *headCommitOid); updateLastCommit->bindParamI(1, repository.repoid); @@ -153,7 +147,8 @@ namespace Gentoo { AdHocFormatter(FindingChanges, "Finding changes for repository %? with range %?...%?"); ChangeSet - writeChangesToFileList(int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, const git_oid & headCommitOid) + writeChangesToFileList( + int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, const git_oid & headCommitOid) { auto log = LOGMANAGER()->getLogger(__FUNCTION__); log->messagectf<FindingChanges>(IceTray::Logging::LogLevel::DEBUG, repoId, lastCommitOid, headCommitOid); @@ -163,7 +158,8 @@ namespace Gentoo { auto headTree = gitSafeGet(git_commit_tree, git_tree_free, headCommit.get()); auto diff = gitSafeGet(git_diff_tree_to_tree, git_diff_free, repo, lastTree.get(), headTree.get(), nullptr); ChangeSet changes; - gitSafe(git_diff_foreach, diff.get(), insertFileChangeT<float>, insertFileChangeT<const git_diff_binary *>, nullptr, nullptr, &changes); + gitSafe(git_diff_foreach, diff.get(), insertFileChangeT<float>, insertFileChangeT<const git_diff_binary *>, + nullptr, nullptr, &changes); return changes; } @@ -173,7 +169,8 @@ namespace Gentoo { { try { auto properties = c.adapter->getCommunicator()->getProperties(); - auto repoRoot = std::filesystem::path(properties->getPropertyWithDefault("GentooBrowseAPI.RepoRoot", "/")); + auto repoRoot + = std::filesystem::path(properties->getPropertyWithDefault("GentooBrowseAPI.RepoRoot", "/")); auto dbc = db->get(); DB::TransactionScope tx(*dbc.get()); for (const auto & repo : fetch<Gentoo::Repositories>(dbc.get(), sql::maintenance::reposToGitRefresh)) { @@ -182,7 +179,8 @@ namespace Gentoo { } time_t now = time(nullptr); sd_notifyf(0, "STATUS=Last update %s", ctime(&now)); - AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::OK, "Package tree(s) updated"); + AdHoc::submitNagiosPassiveServiceCheck( + NagiosServiceName, AdHoc::NagiosStatusCode::OK, "Package tree(s) updated"); } catch (const std::exception & ex) { AdHoc::submitNagiosPassiveServiceCheck(NagiosServiceName, AdHoc::NagiosStatusCode::Warning, ex.what()); @@ -193,7 +191,8 @@ namespace Gentoo { AdHocFormatter(UpdatingFileContent, "Updating file content"); AdHocFormatter(UpdatedFileContent, "Updated file content"); void - Maintenance::applyFileChanges(DB::Connection * dbc, const std::filesystem::path & repoRoot, const Repository & repo, ChangeSet & changes) const + Maintenance::applyFileChanges(DB::Connection * dbc, const std::filesystem::path & repoRoot, + const Repository & repo, ChangeSet & changes) const { auto log = LOGMANAGER()->getLogger(__FUNCTION__); log->messagectf<UpdatingFileContent>(IceTray::Logging::LogLevel::DEBUG); @@ -201,13 +200,16 @@ namespace Gentoo { std::map<unsigned char, std::multimap<unsigned char, FileProcessorPtr>> fps; for (const auto & fpf : AdHoc::PluginManager::getDefault()->getAll<FileProcessorFactory>()) { FileProcessorPtr processor(fpf->implementation()->create()); - fps[processor->phase()].insert({ processor->order(), processor })->second->prepare(dbc); + fps[processor->phase()].insert({processor->order(), processor})->second->prepare(dbc); } // Processor -> repoId, PathParts, Path - typedef std::function<void(FileProcessorPtr, int64_t, const Gentoo::StringList &, const std::filesystem::path &)> FileHandleFunc; + typedef std::function<void( + FileProcessorPtr, int64_t, const Gentoo::StringList &, const std::filesystem::path &)> + FileHandleFunc; std::map<git_delta_t, FileHandleFunc> funcs; funcs[GIT_DELTA_DELETED] = std::bind(&AbstractFileProcessor::deleted, pl::_1, dbc, pl::_2, pl::_3); - funcs[GIT_DELTA_MODIFIED] = std::bind(&AbstractFileProcessor::modified, pl::_1, dbc, pl::_2, pl::_3, pl::_4); + funcs[GIT_DELTA_MODIFIED] + = std::bind(&AbstractFileProcessor::modified, pl::_1, dbc, pl::_2, pl::_3, pl::_4); funcs[GIT_DELTA_ADDED] = std::bind(&AbstractFileProcessor::created, pl::_1, dbc, pl::_2, pl::_3, pl::_4); const auto repoPath = repoRoot / std::filesystem::path(repo.path).lexically_relative("/"); @@ -218,9 +220,10 @@ namespace Gentoo { for (const auto & processorOrder : phase.second) { auto processor = processorOrder.second; // Changes - for (auto change = changes.begin(); change != changes.end(); ) { + for (auto change = changes.begin(); change != changes.end();) { if (processor->match(change->second.pathParts)) { - funcs[change->second.changeType](processor, repo.repoid, change->second.pathParts, repoPath / change->first); + funcs[change->second.changeType]( + processor, repo.repoid, change->second.pathParts, repoPath / change->first); usedProcessors.insert(processor); change = changes.erase(change); } @@ -246,4 +249,3 @@ namespace Gentoo { } } - diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h index 8aece5b..bad2a76 100644 --- a/gentoobrowse-api/service/maintenanceimpl.h +++ b/gentoobrowse-api/service/maintenanceimpl.h @@ -1,45 +1,44 @@ #ifndef MAINTENANCEIMPL_H #define MAINTENANCEIMPL_H +#include "changeSet.h" +#include "maintenance/abstractFileProcessor.h" #include <Ice/Properties.h> -#include <maintenance.h> -#include <visibility.h> +#include <IceUtil/Timer.h> #include <abstractDatabaseClient.h> -#include <map> #include <converters.h> -#include "maintenance/abstractFileProcessor.h" -#include <IceUtil/Timer.h> -#include "changeSet.h" +#include <maintenance.h> +#include <map> +#include <visibility.h> namespace Gentoo { namespace Service { class DLL_PUBLIC Maintenance : public Gentoo::Maintenance, public IceTray::AbstractDatabaseClient { - public: - Maintenance(const DB::ConnectionPoolPtr & d, const Ice::CommunicatorPtr & ic, const Ice::PropertiesPtr & p); - virtual ~Maintenance(); + public: + Maintenance(const DB::ConnectionPoolPtr & d, const Ice::CommunicatorPtr & ic, const Ice::PropertiesPtr & p); + virtual ~Maintenance(); - void refreshPackageTree(const Ice::Current &) override; - void refreshBugs(const Ice::Current &) override; - void updateRepositories(const Ice::Current &) override; - Gentoo::UserNews getUserNews(const Ice::Current &) override; - void sendNotifications(const Ice::Current &) override; + void refreshPackageTree(const Ice::Current &) override; + void refreshBugs(const Ice::Current &) override; + void updateRepositories(const Ice::Current &) override; + Gentoo::UserNews getUserNews(const Ice::Current &) override; + void sendNotifications(const Ice::Current &) override; - protected: - Maintenance(const DB::ConnectionPoolPtr & d); - void applyFileChanges(DB::Connection *, const std::filesystem::path &, const Repository &, ChangeSet &) const; + protected: + Maintenance(const DB::ConnectionPoolPtr & d); + void applyFileChanges( + DB::Connection *, const std::filesystem::path &, const Repository &, ChangeSet &) const; - private: - template<typename Task> - void addTask(Ice::CommunicatorPtr ic, Ice::PropertiesPtr p, const std::string & whenCfg); + private: + template<typename Task> + void addTask(Ice::CommunicatorPtr ic, Ice::PropertiesPtr p, const std::string & whenCfg); - static Ice::PropertiesPtr properties(const Ice::Current &); + static Ice::PropertiesPtr properties(const Ice::Current &); - template <typename T> - static FileProcessorPtr createFileProessor(); - IceUtil::TimerPtr taskRunner; + template<typename T> static FileProcessorPtr createFileProessor(); + IceUtil::TimerPtr taskRunner; }; } } #endif - diff --git a/gentoobrowse-api/service/mask.cpp b/gentoobrowse-api/service/mask.cpp index fd8da40..4d8975c 100644 --- a/gentoobrowse-api/service/mask.cpp +++ b/gentoobrowse-api/service/mask.cpp @@ -1,5 +1,5 @@ -#include <mask.h> #include <lexer-regex.h> +#include <mask.h> namespace Portage { namespace Utils { @@ -12,35 +12,32 @@ namespace Portage { static AdHoc::Lexer::PatternPtr discard = AdHoc::LexerMatchers::regex("^([^\n]*)$\n?", G_REGEX_MULTILINE); Masks::Masks() : - AdHoc::Lexer({ - { { AdHoc::Lexer::InitialState }, maskHead, [&](auto e) - { - person = e->pattern()->match(1); - email = e->pattern()->match(3); - date = *e->pattern()->match(4); - e->pushState("mask"); - } }, - { { "mask" }, maskDesc, [&](auto e) - { - message.push_back(*e->pattern()->match(1)); - } }, - { { "mask" }, atom, [&](auto e) - { - atoms.insert(*e->pattern()->match(1)); - } }, - { { "mask" }, end, [&](auto e) - { - ++n; - consume(); - atoms.clear(); - message.clear(); - e->popState(); - } }, - { { AdHoc::Lexer::InitialState }, discard, [&](auto) { } } - }), + AdHoc::Lexer({{{AdHoc::Lexer::InitialState}, maskHead, + [&](auto e) { + person = e->pattern()->match(1); + email = e->pattern()->match(3); + date = *e->pattern()->match(4); + e->pushState("mask"); + }}, + {{"mask"}, maskDesc, + [&](auto e) { + message.push_back(*e->pattern()->match(1)); + }}, + {{"mask"}, atom, + [&](auto e) { + atoms.insert(*e->pattern()->match(1)); + }}, + {{"mask"}, end, + [&](auto e) { + ++n; + consume(); + atoms.clear(); + message.clear(); + e->popState(); + }}, + {{AdHoc::Lexer::InitialState}, discard, [&](auto) {}}}), n(0) { } } } - diff --git a/gentoobrowse-api/service/mask.h b/gentoobrowse-api/service/mask.h index a739fe5..e4a3748 100644 --- a/gentoobrowse-api/service/mask.h +++ b/gentoobrowse-api/service/mask.h @@ -1,27 +1,26 @@ #ifndef GENTOOBROWSE_SERVICE_MASK_H #define GENTOOBROWSE_SERVICE_MASK_H +#include <glibmm/ustring.h> #include <lexer.h> #include <list> -#include <glibmm/ustring.h> #include <optional> namespace Portage { namespace Utils { class Masks : public AdHoc::Lexer { - protected: - Masks(); + protected: + Masks(); - virtual void consume() const = 0; + virtual void consume() const = 0; - Glib::ustring date; - std::optional<Glib::ustring> person, email; - std::set<std::string> atoms; - std::list<std::string> message; - int n; + Glib::ustring date; + std::optional<Glib::ustring> person, email; + std::set<std::string> atoms; + std::list<std::string> message; + int n; }; } } #endif - diff --git a/gentoobrowse-api/service/news.cpp b/gentoobrowse-api/service/news.cpp index 3bc7aa8..15877c0 100644 --- a/gentoobrowse-api/service/news.cpp +++ b/gentoobrowse-api/service/news.cpp @@ -2,20 +2,30 @@ #include <boost/algorithm/string/split.hpp> #include <lexer-regex.h> -AdHoc::Lexer::PatternPtr Title(AdHoc::LexerMatchers::regex("^Title: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr DisplayIfInstalled(AdHoc::LexerMatchers::regex("^Display-If-Installed: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr Author(AdHoc::LexerMatchers::regex("^Author: (.+) <([^>]+)>$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr Posted(AdHoc::LexerMatchers::regex("^Posted: ([0-9]{4}-[0-9]{2}-[0-9]{2})$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr IgnoredHeader(AdHoc::LexerMatchers::regex("^[^ :]+: .+$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr BlankLine(AdHoc::LexerMatchers::regex("^$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr BodyText(AdHoc::LexerMatchers::regex("^(.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); -AdHoc::Lexer::PatternPtr Link(AdHoc::LexerMatchers::regex("^\\[[[:digit:]]+\\] ([[:alpha:]]+://.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr Title( + AdHoc::LexerMatchers::regex("^Title: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr DisplayIfInstalled(AdHoc::LexerMatchers::regex( + "^Display-If-Installed: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr Author(AdHoc::LexerMatchers::regex( + "^Author: (.+) <([^>]+)>$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr Posted(AdHoc::LexerMatchers::regex( + "^Posted: ([0-9]{4}-[0-9]{2}-[0-9]{2})$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr IgnoredHeader( + AdHoc::LexerMatchers::regex("^[^ :]+: .+$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr BlankLine( + AdHoc::LexerMatchers::regex("^$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr BodyText( + AdHoc::LexerMatchers::regex("^(.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); +AdHoc::Lexer::PatternPtr Link(AdHoc::LexerMatchers::regex( + "^\\[[[:digit:]]+\\] ([[:alpha:]]+://.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE))); const std::string Body("Body"); namespace Portage { namespace Utils { - template<typename T, typename Y> Ice::optional<T> iuo(const std::optional<Y> & x) + template<typename T, typename Y> + Ice::optional<T> + iuo(const std::optional<Y> & x) { if (x) { return Ice::optional<T>(*x); @@ -23,59 +33,68 @@ namespace Portage { return Ice::optional<T>(); } - template<typename T, typename Y> std::vector<T> split(const std::optional<Y> & x) + template<typename T, typename Y> + std::vector<T> + split(const std::optional<Y> & x) { std::vector<T> rtn; if (x) { - boost::algorithm::split(rtn, *x, [](auto c) { return c == ','; }); + boost::algorithm::split(rtn, *x, [](auto c) { + return c == ','; + }); std::sort(rtn.begin(), rtn.end()); } return rtn; } News::News() : - AdHoc::Lexer({ - // title: words - { { InitialState }, Title, [this](auto es) { - news->title = *es->pattern()->match(1); - } }, - // posted: date - { { InitialState }, Posted, [this](auto es) { - news->posted = *es->pattern()->match(1); - } }, - // display-if-installed: atomspec - { { InitialState }, DisplayIfInstalled, [this](auto es) { - news->atomspec.push_back(*es->pattern()->match(1)); - } }, - // author: name <email> - { { InitialState }, Author, [this](auto es) { - news->authorname = es->pattern()->match(1)->raw(); - news->authoremail = es->pattern()->match(2)->raw(); - } }, - // other headers - { { InitialState }, IgnoredHeader, [](auto) { - } }, - // blank - { { InitialState }, BlankLine, [this](auto es) { - es->setState(Body); - news->body.push_back(std::string()); - } }, - // body blank - { { Body }, BlankLine, [this](auto) { - news->body.push_back(std::string()); - } }, - // link - { { Body }, Link, [this](auto es) { - news->urls.push_back(*es->pattern()->match(1)); - } }, - // body text - { { Body }, BodyText, [this](auto es) { - if (!news->body.back().empty()) { - news->body.back().append(" "); - } - news->body.back().append(*es->pattern()->match(1)); - } } - }), + AdHoc::Lexer({// title: words + {{InitialState}, Title, + [this](auto es) { + news->title = *es->pattern()->match(1); + }}, + // posted: date + {{InitialState}, Posted, + [this](auto es) { + news->posted = *es->pattern()->match(1); + }}, + // display-if-installed: atomspec + {{InitialState}, DisplayIfInstalled, + [this](auto es) { + news->atomspec.push_back(*es->pattern()->match(1)); + }}, + // author: name <email> + {{InitialState}, Author, + [this](auto es) { + news->authorname = es->pattern()->match(1)->raw(); + news->authoremail = es->pattern()->match(2)->raw(); + }}, + // other headers + {{InitialState}, IgnoredHeader, [](auto) {}}, + // blank + {{InitialState}, BlankLine, + [this](auto es) { + es->setState(Body); + news->body.push_back(std::string()); + }}, + // body blank + {{Body}, BlankLine, + [this](auto) { + news->body.push_back(std::string()); + }}, + // link + {{Body}, Link, + [this](auto es) { + news->urls.push_back(*es->pattern()->match(1)); + }}, + // body text + {{Body}, BodyText, + [this](auto es) { + if (!news->body.back().empty()) { + news->body.back().append(" "); + } + news->body.back().append(*es->pattern()->match(1)); + }}}), news(std::make_shared<Gentoo::NewsItem>()) { } @@ -85,11 +104,12 @@ namespace Portage { { News d; d.extract(str.data(), str.length()); - d.news->body.erase( - std::remove_if(d.news->body.begin(), d.news->body.end(), [](const auto & s) { return s.empty(); }), - d.news->body.end()); + d.news->body.erase(std::remove_if(d.news->body.begin(), d.news->body.end(), + [](const auto & s) { + return s.empty(); + }), + d.news->body.end()); return d.news; } } } - diff --git a/gentoobrowse-api/service/news.h b/gentoobrowse-api/service/news.h index 0d2e26f..23e3d12 100644 --- a/gentoobrowse-api/service/news.h +++ b/gentoobrowse-api/service/news.h @@ -2,22 +2,21 @@ #define GENTOOBROWSE_SERVICE_NEWS_H #include <istream> -#include <vector> -#include <portage-models.h> #include <lexer.h> +#include <portage-models.h> +#include <vector> namespace Portage { namespace Utils { class News : AdHoc::Lexer { - private: - News(); + private: + News(); - public: - Gentoo::NewsItemPtr news; - static Gentoo::NewsItemPtr parse(const std::basic_string_view<gchar> &); + public: + Gentoo::NewsItemPtr news; + static Gentoo::NewsItemPtr parse(const std::basic_string_view<gchar> &); }; } } #endif - diff --git a/gentoobrowse-api/service/notifications/css/style.css b/gentoobrowse-api/service/notifications/css/style.css index 912234e..cc3f164 100644 --- a/gentoobrowse-api/service/notifications/css/style.css +++ b/gentoobrowse-api/service/notifications/css/style.css @@ -1,50 +1,252 @@ -body{position:relative;padding-top:40px} -body>.navbar{font-size:13px} -body>.navbar .brand{padding-right:0;padding-left:0;margin-left:20px;float:right;font-weight:bold;color:#000;text-shadow:0 1px 0 rgba(255,255,255,.1),0 0 30px rgba(255,255,255,.125);-webkit-transition:all .2s linear;-moz-transition:all .2s linear;transition:all .2s linear} -body>.navbar .brand:hover{text-decoration:none;text-shadow:0 1px 0 rgba(255,255,255,.1),0 0 30px rgba(255,255,255,.4)} -section>.page-header{color:#5a5a5a} -.jumbotron{position:relative;padding:25px 0;color:#fff;text-align:center;text-shadow:0 1px 3px rgba(0,0,0,.4),0 0 30px rgba(0,0,0,.075);background:#020031;background:-moz-linear-gradient(45deg,#020031 0,#6d3353 100%);background:-webkit-gradient(linear,left bottom,right top,color-stop(0,#020031),color-stop(100%,#6d3353));background:-webkit-linear-gradient(45deg,#020031 0,#6d3353 100%);background:-o-linear-gradient(45deg,#020031 0,#6d3353 100%);background:-ms-linear-gradient(45deg,#020031 0,#6d3353 100%);background:linear-gradient(45deg,#020031 0,#6d3353 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#020031',endColorstr='#6d3353',GradientType=1);-webkit-box-shadow:inset 0 3px 7px rgba(0,0,0,.2),inset 0 -3px 7px rgba(0,0,0,.2);-moz-box-shadow:inset 0 3px 7px rgba(0,0,0,.2),inset 0 -3px 7px rgba(0,0,0,.2);box-shadow:inset 0 3px 7px rgba(0,0,0,.2),inset 0 -3px 7px rgba(0,0,0,.2)} -.jumbotron h1{font-size:80px;font-weight:bold;letter-spacing:-1px;line-height:1} -.jumbotron .container{position:relative;z-index:2} -.jumbotron:after{content:'';display:block;position:absolute;top:0;right:0;bottom:0;left:0;opacity:.4} -@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min--moz-device-pixel-ratio:2),only screen and (-o-min-device-pixel-ratio:2/1){ -.jumbotron:after{background-size:150px 150px} -} -.subhead{text-align:left;border-bottom:1px solid #ddd} -.subhead h1{font-size:50px} -.footer{text-align:center;padding:30px 0;margin-top:70px;border-top:1px solid #e5e5e5;background-color:#f5f5f5} -.footer p{margin-bottom:0;color:#777} -.footer-links{margin:10px 0} -.footer-links li{display:inline;padding:0 2px} -.footer-links li:first-child{padding-left:0} -.bs-docs-sidenav{width:208px;margin:20px 0 0;padding:0;background-color:#fff;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 1px 4px rgba(0,0,0,.065);-moz-box-shadow:0 1px 4px rgba(0,0,0,.065);box-shadow:0 1px 4px rgba(0,0,0,.065)} -.bs-docs-sidenav>li>a{display:block;width:190px \9;margin:0 0 -1px;padding:4px 10px;border:1px solid #e5e5e5} -.bs-docs-sidenav>li:first-child>a{-webkit-border-radius:6px 6px 0 0;-moz-border-radius:6px 6px 0 0;border-radius:6px 6px 0 0} -.bs-docs-sidenav>li:last-child>a{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px} -.bs-docs-sidenav i{float:right;margin-top:2px;margin-right:-6px;opacity:.25} -.bs-docs-sidenav>li>a:hover{background-color:#f5f5f5} -.bs-docs-sidenav a:hover i{opacity:.5} -@media (min-width:1200px){ -.bs-docs-sidenav{width:258px} -.bs-docs-sidenav>li>a{width:230px \9} -} -@media (max-width:980px){body>.navbar-fixed-top .brand{float:left;margin-left:0;padding-left:10px;padding-right:10px} -.bs-docs-sidenav{top:0;width:218px;margin-top:30px;margin-right:0} -} -@media (min-width:768px) and (max-width:979px){body{padding-top:0} -.jumbotron{margin-top:-20px} -.bs-docs-sidenav{width:166px;margin-top:20px} -} -@media (max-width:767px){body{padding-top:0} -.jumbotron{padding:40px 20px;margin-top:-20px;margin-right:-20px;margin-left:-20px} -.bs-docs-sidenav{width:auto;margin-bottom:20px} -.footer{margin-left:-20px;margin-right:-20px;padding-left:20px;padding-right:20px} -.footer p{margin-bottom:9px} -} -@media (max-width:480px){body{padding-top:0} -.jumbotron h1{font-size:45px} -.subhead h1{text-align:center} -.footer{padding-top:20px;padding-bottom:20px} -} -a{cursor:pointer} -ul.footer-links li::before, ul.footer-links li:last-child::after {content:'·';color:#999} +body +{ +position: + relative; + padding - top : 40px +} +body >.navbar {font - size: 13px} body >.navbar.brand +{ + padding - right : 0; + padding - left : 0; + margin - left : 20px; + float : right; + font - weight : bold; +color: +# 000; + text - shadow : 0 1px 0 rgba(255, 255, 255, .1), 0 0 30px rgba(255, 255, 255, .125); + -webkit - transition : all .2s linear; + -moz - transition : all .2s linear; +transition: + all .2s linear +} +body >.navbar.brand : hover +{ + text - decoration : none; + text - shadow : 0 1px 0 rgba(255, 255, 255, .1), 0 0 30px rgba(255, 255, 255, .4) +} +section >.page - header {color: #5a5a5a}.jumbotron +{ +position: + relative; +padding: + 25px 0; +color: +# fff; + text - align : center; + text - shadow : 0 1px 3px rgba(0, 0, 0, .4), 0 0 30px rgba(0, 0, 0, .075); +background: +# 020031; +background: + -moz - linear - gradient(45deg, #020031 0, #6d3353 100 %); +background: + -webkit - gradient(linear, left bottom, right top, color - stop(0, #020031), color - stop(100 %, #6d3353)); +background: + -webkit - linear - gradient(45deg, #020031 0, #6d3353 100 %); +background: + -o - linear - gradient(45deg, #020031 0, #6d3353 100 %); +background: + -ms - linear - gradient(45deg, #020031 0, #6d3353 100 %); +background: + linear - gradient(45deg, #020031 0, #6d3353 100 %); +filter: +progid: + DXImageTransform.Microsoft.gradient(startColorstr = '#020031', endColorstr = '#6d3353', GradientType = 1); + -webkit - box - shadow : inset 0 3px 7px rgba(0, 0, 0, .2), inset 0 - 3px 7px rgba(0, 0, 0, .2); + -moz - box - shadow : inset 0 3px 7px rgba(0, 0, 0, .2), inset 0 - 3px 7px rgba(0, 0, 0, .2); + box - shadow : inset 0 3px 7px rgba(0, 0, 0, .2), inset 0 - 3px 7px rgba(0, 0, 0, .2) +} +.jumbotron h1 +{ + font - size : 80px; + font - weight : bold; + letter - spacing : -1px; + line - height : 1 +} +.jumbotron.container +{ +position: + relative; + z - index : 2 +} +.jumbotron : after +{ +content: + ''; +display: + block; +position: + absolute; +top: + 0; +right: + 0; +bottom: + 0; +left: + 0; +opacity: + .4 +} +@media only screen and (-webkit - min - device - pixel - ratio : 2), + only screen and (min-- moz - device - pixel - ratio : 2), + only screen + and (-o - min - device - pixel - ratio : 2 / 1) {.jumbotron: after {background - size: 150px 150px}}.subhead +{ + text - align : left; + border - bottom : 1px solid #ddd +} +.subhead h1 {font - size: 50px}.footer +{ + text - align : center; +padding: + 30px 0; + margin - top : 70px; + border - top : 1px solid #e5e5e5; + background - color : #f5f5f5 +} +.footer p +{ + margin - bottom : 0; +color: +# 777 +} +.footer - links {margin: 10px 0}.footer - links li +{ +display: + inline; +padding: + 0 2px +} +.footer - links li : first - child {padding - left: 0}.bs - docs - sidenav +{ +width: + 208px; +margin: + 20px 0 0; +padding: + 0; + background - color : #fff; + -webkit - border - radius : 6px; + -moz - border - radius : 6px; + border - radius : 6px; + -webkit - box - shadow : 0 1px 4px rgba(0, 0, 0, .065); + -moz - box - shadow : 0 1px 4px rgba(0, 0, 0, .065); + box - shadow : 0 1px 4px rgba(0, 0, 0, .065) +} +.bs - docs - sidenav > li > a +{ +display: + block; +width: + 190px \9; +margin: + 0 0 - 1px; +padding: + 4px 10px; +border: + 1px solid #e5e5e5 +} +.bs - docs - sidenav > li : first - child > a +{ + -webkit - border - radius : 6px 6px 0 0; + -moz - border - radius : 6px 6px 0 0; + border - radius : 6px 6px 0 0 +} +.bs - docs - sidenav > li : last - child > a +{ + -webkit - border - radius : 0 0 6px 6px; + -moz - border - radius : 0 0 6px 6px; + border - radius : 0 0 6px 6px +} +.bs - docs - sidenav i +{ + float : right; + margin - top : 2px; + margin - right : -6px; +opacity: + .25 +} +.bs - docs - sidenav > li > a : hover {background - color: #f5f5f5}.bs - docs - sidenav a : hover i +{ +opacity: + .5 +} +@media(min - width : 1200px) +{ + .bs - docs - sidenav {width: 258px}.bs - docs - sidenav > li > a + { + width: + 230px \9 + } +} +@media(max - width : 980px) +{ + body >.navbar - fixed - top.brand + { + float : left; + margin - left : 0; + padding - left : 10px; + padding - right : 10px + } + .bs - docs - sidenav + { + top: + 0; + width: + 218px; + margin - top : 30px; + margin - right : 0 + } +} +@media(min - width : 768px) and (max - width : 979px) +{ + body {padding - top: 0}.jumbotron {margin - top: -20px}.bs - docs - sidenav + { + width: + 166px; + margin - top : 20px + } +} +@media(max - width : 767px) +{ + body {padding - top: 0}.jumbotron + { + padding: + 40px 20px; + margin - top : -20px; + margin - right : -20px; + margin - left : -20px + } + .bs - docs - sidenav + { + width: + auto; + margin - bottom : 20px + } + .footer + { + margin - left : -20px; + margin - right : -20px; + padding - left : 20px; + padding - right : 20px + } + .footer p + { + margin - bottom : 9px + } +} +@media(max - width : 480px) +{ + body {padding - top: 0}.jumbotron h1 {font - size: 45px}.subhead h1 {text - align: center}.footer + { + padding - top : 20px; + padding - bottom : 20px + } +} +a {cursor: pointer} ul.footer - links li::before, ul.footer - links li : last - child::after +{ +content: + '·'; +color: +# 999 +} diff --git a/gentoobrowse-api/service/notificationsimpl.cpp b/gentoobrowse-api/service/notificationsimpl.cpp index c15bc4f..ad5ac91 100644 --- a/gentoobrowse-api/service/notificationsimpl.cpp +++ b/gentoobrowse-api/service/notificationsimpl.cpp @@ -1,20 +1,21 @@ #include "notificationsimpl.h" +#include "xsltStreamSerializer.h" #include <libxml/parser.h> #include <notifications/xslt/base.h> #include <notifications/xslt/news.h> #include <notifications/xslt/signup.h> -#include <string.h> #include <slicer/slicer.h> -#include "xsltStreamSerializer.h" +#include <string.h> namespace Gentoo { namespace Service { - xmlDocPtr xsltDocLoaderFunc (const xmlChar * URI, xmlDictPtr, int, void *, xsltLoadType) + xmlDocPtr + xsltDocLoaderFunc(const xmlChar * URI, xmlDictPtr, int, void *, xsltLoadType) { #define MATCH(name) \ - if (xmlStrcmp(URI, BAD_CAST #name ".xslt") == 0) { \ - return xmlParseMemory((char *)name ## _xslt, name ## _xslt_len); \ - } + if (xmlStrcmp(URI, BAD_CAST #name ".xslt") == 0) { \ + return xmlParseMemory((char *)name##_xslt, name##_xslt_len); \ + } MATCH(base) MATCH(news) MATCH(signup) @@ -30,21 +31,24 @@ namespace Gentoo { xsltSetLoaderFunc(NULL); } - IceTray::Mail::EmailPtr Notifications::getSignup(const Gentoo::NewUserPtr & u) + IceTray::Mail::EmailPtr + Notifications::getSignup(const Gentoo::NewUserPtr & u) { auto e = basicMail("Welcome", u); Slicer::SerializeAny<XsltStreamSerializer>(u, e, signup.get()); return e; } - IceTray::Mail::EmailPtr Notifications::getNews(const Gentoo::UserPtr & u, const Gentoo::NewsContent & c) + IceTray::Mail::EmailPtr + Notifications::getNews(const Gentoo::UserPtr & u, const Gentoo::NewsContent & c) { auto e = basicMail("Latest updates", u); Slicer::SerializeAny<XsltStreamSerializer>(c, e, news.get()); return e; } - IceTray::Mail::EmailPtr Notifications::basicMail(const std::string & subject, const Gentoo::UserPtr & u) + IceTray::Mail::EmailPtr + Notifications::basicMail(const std::string & subject, const Gentoo::UserPtr & u) { auto e = std::make_shared<IceTray::Mail::Email>(); e->subject = "Gentoo Browse: " + subject; @@ -56,4 +60,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/notificationsimpl.h b/gentoobrowse-api/service/notificationsimpl.h index 9aef9f4..4ce0f26 100644 --- a/gentoobrowse-api/service/notificationsimpl.h +++ b/gentoobrowse-api/service/notificationsimpl.h @@ -1,29 +1,28 @@ #ifndef NOTIFICATIONSIMPL_H #define NOTIFICATIONSIMPL_H +#include <libxslt/documents.h> +#include <memory> #include <notifications.h> #include <visibility.h> -#include <memory> -#include <libxslt/documents.h> namespace Gentoo { namespace Service { class DLL_PUBLIC Notifications : public Gentoo::Notifications { - public: - Notifications(); + public: + Notifications(); - IceTray::Mail::EmailPtr getSignup(const Gentoo::NewUserPtr &) override; - IceTray::Mail::EmailPtr getNews(const Gentoo::UserPtr &, const Gentoo::NewsContent &) override; + IceTray::Mail::EmailPtr getSignup(const Gentoo::NewUserPtr &) override; + IceTray::Mail::EmailPtr getNews(const Gentoo::UserPtr &, const Gentoo::NewsContent &) override; - private: - IceTray::Mail::EmailPtr basicMail(const std::string &, const Gentoo::UserPtr & u); + private: + IceTray::Mail::EmailPtr basicMail(const std::string &, const Gentoo::UserPtr & u); - typedef std::shared_ptr<xsltStylesheet> xsltSSPtr; - xsltSSPtr news; - xsltSSPtr signup; + typedef std::shared_ptr<xsltStylesheet> xsltSSPtr; + xsltSSPtr news; + xsltSSPtr signup; }; } } #endif - diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index 79757e3..5bceb6b 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -1,311 +1,307 @@ #include "portageimpl.h" -#include <sql/portage/getCategory.sql.h> #include <sql/portage/findCategory.sql.h> +#include <sql/portage/findPackage.sql.h> #include <sql/portage/getAllCategories.sql.h> +#include <sql/portage/getAllOverviewCategories.sql.h> +#include <sql/portage/getAllPackages.sql.h> +#include <sql/portage/getBug.sql.h> +#include <sql/portage/getBugsSearch.sql.h> #include <sql/portage/getCategoriesInSuper.sql.h> #include <sql/portage/getCategoriesWithRecentAdditions.sql.h> +#include <sql/portage/getCategory.sql.h> +#include <sql/portage/getEbuildsByFilter.sql.h> +#include <sql/portage/getGlobalUses.sql.h> +#include <sql/portage/getGroupUses.sql.h> +#include <sql/portage/getNewsItem.sql.h> +#include <sql/portage/getNewsRecent.sql.h> +#include <sql/portage/getNewsSearch.sql.h> #include <sql/portage/getOverviewCategoriesInSuper.sql.h> -#include <sql/portage/getAllOverviewCategories.sql.h> #include <sql/portage/getPackage.sql.h> -#include <sql/portage/findPackage.sql.h> -#include <sql/portage/getAllPackages.sql.h> -#include <sql/portage/getPackagesInCategory.sql.h> -#include <sql/portage/getPackagesSearch.sql.h> -#include <sql/portage/getPackageVersions.sql.h> -#include <sql/portage/getPackageVersionDetails.sql.h> +#include <sql/portage/getPackageBugs.sql.h> #include <sql/portage/getPackageChangeLog.sql.h> -#include <sql/portage/getPackagesWithRecentAdditions.sql.h> -#include <sql/portage/getTopTrackedPackages.sql.h> -#include <sql/portage/getUserTrackedPackages.sql.h> -#include <sql/portage/getUserTrackedRecentVersions.sql.h> -#include <sql/portage/getRecentAdditions.sql.h> #include <sql/portage/getPackageDependencies.sql.h> -#include <sql/portage/getPackageRuntimeDependencies.sql.h> -#include <sql/portage/getPackagesDepending.sql.h> #include <sql/portage/getPackageMasks.sql.h> +#include <sql/portage/getPackageRuntimeDependencies.sql.h> +#include <sql/portage/getPackageUrls.sql.h> #include <sql/portage/getPackageUses.sql.h> -#include <sql/portage/getEbuildsByFilter.sql.h> +#include <sql/portage/getPackageVersionDetails.sql.h> +#include <sql/portage/getPackageVersions.sql.h> +#include <sql/portage/getPackagesDepending.sql.h> +#include <sql/portage/getPackagesInCategory.sql.h> +#include <sql/portage/getPackagesSearch.sql.h> +#include <sql/portage/getPackagesWithRecentAdditions.sql.h> +#include <sql/portage/getRecentAdditions.sql.h> +#include <sql/portage/getRepositories.sql.h> +#include <sql/portage/getRepository.sql.h> +#include <sql/portage/getTopTrackedPackages.sql.h> #include <sql/portage/getUse.sql.h> -#include <sql/portage/getGlobalUses.sql.h> -#include <sql/portage/getGroupUses.sql.h> #include <sql/portage/getUseGroups.sql.h> -#include <sql/portage/getUseUsage.sql.h> #include <sql/portage/getUsePackages.sql.h> +#include <sql/portage/getUseUsage.sql.h> +#include <sql/portage/getUserTrackedPackages.sql.h> +#include <sql/portage/getUserTrackedRecentVersions.sql.h> #include <sql/portage/getUsesSearch.sql.h> -#include <sql/portage/getBug.sql.h> -#include <sql/portage/getPackageBugs.sql.h> -#include <sql/portage/getBugsSearch.sql.h> -#include <sql/portage/getNewsItem.sql.h> -#include <sql/portage/getNewsSearch.sql.h> -#include <sql/portage/getNewsRecent.sql.h> -#include <sql/portage/getRepository.sql.h> -#include <sql/portage/getRepositories.sql.h> -#include <sql/portage/getPackageUrls.sql.h> namespace Gentoo { -namespace Service { -Portage::Portage(const DB::ConnectionPoolPtr & d) : - IceTray::AbstractCachingDatabaseClient(d) -{ -} - -Gentoo::CategoryPtr -Portage::getCategory(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::CategoryPtr>(sql::portage::getCategory, 30, id); -} - -Gentoo::CategoryPtr -Portage::findCategory(const std::string_view name, const Ice::Current &) -{ - return fetchCache<Gentoo::CategoryPtr>(sql::portage::findCategory, 30, name); -} - -Gentoo::Categories -Portage::getAllCategories(const Ice::Current &) -{ - return fetchCache<Gentoo::Categories>(sql::portage::getAllCategories, 30); -} - -Gentoo::Categories -Portage::getCategoriesInSuper(const std::string_view super, const Ice::Current &) -{ - return fetchCache<Gentoo::Categories>(sql::portage::getCategoriesInSuper, 30, super); -} - -Gentoo::OverviewCategoriesBySuper -Portage::getAllOverviewCategories(const Ice::Current &) -{ - Gentoo::OverviewCategoriesBySuper rtn; - auto cats = fetchCache<Gentoo::OverviewCategories>(sql::portage::getAllOverviewCategories, 30); - for (const auto & c : cats) { - auto hyphen = c->name.find('-'); - rtn[c->name.substr(0, hyphen)].push_back(c); + namespace Service { + Portage::Portage(const DB::ConnectionPoolPtr & d) : IceTray::AbstractCachingDatabaseClient(d) { } + + Gentoo::CategoryPtr + Portage::getCategory(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::CategoryPtr>(sql::portage::getCategory, 30, id); + } + + Gentoo::CategoryPtr + Portage::findCategory(const std::string_view name, const Ice::Current &) + { + return fetchCache<Gentoo::CategoryPtr>(sql::portage::findCategory, 30, name); + } + + Gentoo::Categories + Portage::getAllCategories(const Ice::Current &) + { + return fetchCache<Gentoo::Categories>(sql::portage::getAllCategories, 30); + } + + Gentoo::Categories + Portage::getCategoriesInSuper(const std::string_view super, const Ice::Current &) + { + return fetchCache<Gentoo::Categories>(sql::portage::getCategoriesInSuper, 30, super); + } + + Gentoo::OverviewCategoriesBySuper + Portage::getAllOverviewCategories(const Ice::Current &) + { + Gentoo::OverviewCategoriesBySuper rtn; + auto cats = fetchCache<Gentoo::OverviewCategories>(sql::portage::getAllOverviewCategories, 30); + for (const auto & c : cats) { + auto hyphen = c->name.find('-'); + rtn[c->name.substr(0, hyphen)].push_back(c); + } + return rtn; + } + + Gentoo::OverviewCategories + Portage::getOverviewCategoriesInSuper(const std::string_view super, const Ice::Current &) + { + return fetchCache<Gentoo::OverviewCategories>(sql::portage::getOverviewCategoriesInSuper, 30, super); + } + + Gentoo::PackagePtr + Portage::getPackage(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::PackagePtr>(sql::portage::getPackage, 30, id); + } + + Gentoo::PackagePtr + Portage::findPackage(const std::string_view cat, const std::string_view pkg, const Ice::Current &) + { + return fetchCache<Gentoo::PackagePtr>(sql::portage::findPackage, 30, cat, pkg); + } + + Gentoo::Packages + Portage::getAllPackages(const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getAllPackages, 30); + } + + Gentoo::Packages + Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getPackagesInCategory, 30, id); + } + + Gentoo::SearchResultPackages + Portage::getPackagesSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache<Gentoo::SearchResultPackages>(sql::portage::getPackagesSearch, 30, query, query); + } + + Gentoo::Ebuilds + Portage::getPackageVersions(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::Ebuilds>(sql::portage::getPackageVersions, 30, id); + } + + Gentoo::EbuildDetails + Portage::getPackageVersionDetails(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::EbuildDetails>(sql::portage::getPackageVersionDetails, 30, id); + } + + Gentoo::ChangeLog + Portage::getPackageChangeLog(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::ChangeLog>(sql::portage::getPackageChangeLog, 30, id); + } + + Gentoo::Ebuilds + Portage::getRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache<Gentoo::Ebuilds>(sql::portage::getRecentAdditions, 30, syncDays); + } + + Gentoo::Packages + Portage::getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getPackagesWithRecentAdditions, 30, syncDays); + } + + Gentoo::Packages + Portage::getTopTrackedPackages(Ice::Int n, const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getTopTrackedPackages, 30, n); + } + + Gentoo::Packages + Portage::getUserTrackedPackages(Ice::Int userid, const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getUserTrackedPackages, 30, userid); + } + + Gentoo::Ebuilds + Portage::getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) + { + return fetchCache<Gentoo::Ebuilds>(sql::portage::getUserTrackedRecentVersions, 30, userid, limit); + } + + Gentoo::StringList + Portage::getPackageUrls(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::StringList>(sql::portage::getPackageUrls, 30, id); + } + + Gentoo::Ebuilds + Portage::getEbuildsByFilter(const std::string_view filter, const Ice::Current &) + { + return fetchCache<Gentoo::Ebuilds>(sql::portage::getEbuildsByFilter, 30, filter); + } + + Gentoo::Categories + Portage::getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache<Gentoo::Categories>(sql::portage::getCategoriesWithRecentAdditions, 30, syncDays); + } + + Gentoo::PackageDependencyPackages + Portage::getPackageDependencies(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackageDependencies, 30, id); + } + + Gentoo::PackageDependencyPackages + Portage::getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackageRuntimeDependencies, 30, id); + } + + Gentoo::PackageDependencyPackages + Portage::getPackagesDepending(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackagesDepending, 30, id); + } + + Gentoo::PackageMasks + Portage::getPackageMasks(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::PackageMasks>(sql::portage::getPackageMasks, 30, id); + } + + Gentoo::Uses + Portage::getPackageUses(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::Uses>(sql::portage::getPackageUses, 30, id); + } + + Gentoo::UsePtr + Portage::getUse(const std::string_view use, const Ice::Current &) + { + return fetchCache<Gentoo::UsePtr>(sql::portage::getUse, 30, use, use); + } + + Gentoo::Uses + Portage::getGlobalUses(const Ice::Current &) + { + return fetchCache<Gentoo::Uses>(sql::portage::getGlobalUses, 30); + } + + Gentoo::Uses + Portage::getGroupUses(const std::string_view group, const Ice::Current &) + { + return fetchCache<Gentoo::Uses>(sql::portage::getGroupUses, 30, group); + } + + Gentoo::StringList + Portage::getUseGroups(const Ice::Current &) + { + return fetchCache<Gentoo::StringList>(sql::portage::getUseGroups, 30); + } + + Gentoo::Uses + Portage::getUseUsage(const std::string_view use, const Ice::Current &) + { + return fetchCache<Gentoo::Uses>(sql::portage::getUseUsage, 30, use, use, use, use); + } + + Gentoo::Packages + Portage::getUsePackages(const std::string_view use, const Ice::Current &) + { + return fetchCache<Gentoo::Packages>(sql::portage::getUsePackages, 30, use, use); + } + + Gentoo::Uses + Portage::getUsesSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache<Gentoo::Uses>(sql::portage::getUsesSearch, 30, query); + } + + Gentoo::BugPtr + Portage::getBug(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::BugPtr>(sql::portage::getBug, 30, id); + } + + Gentoo::Bugs + Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) + { + return fetchCache<Gentoo::Bugs>(sql::portage::getPackageBugs, 30, packageId); + } + + Gentoo::SearchResultBugs + Portage::getBugsSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache<Gentoo::SearchResultBugs>(sql::portage::getBugsSearch, 30, query, query); + } + + Gentoo::NewsItemPtr + Portage::getNewsItem(const std::string_view id, const Ice::Current &) + { + return fetchCache<Gentoo::NewsItemPtr>(sql::portage::getNewsItem, 30, id); + } + + Gentoo::News + Portage::getNewsSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache<Gentoo::News>(sql::portage::getNewsSearch, 30, query); + } + + Gentoo::News + Portage::getNewsRecent(Ice::Int items, const Ice::Current &) + { + return fetchCache<Gentoo::News>(sql::portage::getNewsRecent, 30, items); + } + + Gentoo::Repository + Portage::getRepository(Ice::Int id, const Ice::Current &) + { + return fetchCache<Gentoo::Repository>(sql::portage::getRepository, 30, id); + } + + Gentoo::Repositories + Portage::getRepositories(const Ice::Current &) + { + return fetchCache<Gentoo::Repositories>(sql::portage::getRepositories, 30); + } } - return rtn; -} - -Gentoo::OverviewCategories -Portage::getOverviewCategoriesInSuper(const std::string_view super, const Ice::Current &) -{ - return fetchCache<Gentoo::OverviewCategories>(sql::portage::getOverviewCategoriesInSuper, 30, super); -} - -Gentoo::PackagePtr -Portage::getPackage(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::PackagePtr>(sql::portage::getPackage, 30, id); -} - -Gentoo::PackagePtr -Portage::findPackage(const std::string_view cat, const std::string_view pkg, const Ice::Current &) -{ - return fetchCache<Gentoo::PackagePtr>(sql::portage::findPackage, 30, cat, pkg); } - -Gentoo::Packages -Portage::getAllPackages(const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getAllPackages, 30); -} - -Gentoo::Packages -Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getPackagesInCategory, 30, id); -} - -Gentoo::SearchResultPackages -Portage::getPackagesSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache<Gentoo::SearchResultPackages>(sql::portage::getPackagesSearch, 30, query, query); -} - -Gentoo::Ebuilds -Portage::getPackageVersions(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::Ebuilds>(sql::portage::getPackageVersions, 30, id); -} - -Gentoo::EbuildDetails -Portage::getPackageVersionDetails(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::EbuildDetails>(sql::portage::getPackageVersionDetails, 30, id); -} - -Gentoo::ChangeLog -Portage::getPackageChangeLog(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::ChangeLog>(sql::portage::getPackageChangeLog, 30, id); -} - -Gentoo::Ebuilds -Portage::getRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache<Gentoo::Ebuilds>(sql::portage::getRecentAdditions, 30, syncDays); -} - -Gentoo::Packages -Portage::getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getPackagesWithRecentAdditions, 30, syncDays); -} - -Gentoo::Packages -Portage::getTopTrackedPackages(Ice::Int n, const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getTopTrackedPackages, 30, n); -} - -Gentoo::Packages -Portage::getUserTrackedPackages(Ice::Int userid, const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getUserTrackedPackages, 30, userid); -} - -Gentoo::Ebuilds -Portage::getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) -{ - return fetchCache<Gentoo::Ebuilds>(sql::portage::getUserTrackedRecentVersions, 30, userid, limit); -} - -Gentoo::StringList -Portage::getPackageUrls(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::StringList>(sql::portage::getPackageUrls, 30, id); -} - -Gentoo::Ebuilds -Portage::getEbuildsByFilter(const std::string_view filter, const Ice::Current &) -{ - return fetchCache<Gentoo::Ebuilds>(sql::portage::getEbuildsByFilter, 30, filter); -} - -Gentoo::Categories -Portage::getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache<Gentoo::Categories>(sql::portage::getCategoriesWithRecentAdditions, 30, syncDays); -} - -Gentoo::PackageDependencyPackages -Portage::getPackageDependencies(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackageDependencies, 30, id); -} - -Gentoo::PackageDependencyPackages -Portage::getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackageRuntimeDependencies, 30, id); -} - -Gentoo::PackageDependencyPackages -Portage::getPackagesDepending(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::PackageDependencyPackages>(sql::portage::getPackagesDepending, 30, id); -} - -Gentoo::PackageMasks -Portage::getPackageMasks(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::PackageMasks>(sql::portage::getPackageMasks, 30, id); -} - -Gentoo::Uses -Portage::getPackageUses(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::Uses>(sql::portage::getPackageUses, 30, id); -} - -Gentoo::UsePtr -Portage::getUse(const std::string_view use, const Ice::Current &) -{ - return fetchCache<Gentoo::UsePtr>(sql::portage::getUse, 30, use, use); -} - -Gentoo::Uses -Portage::getGlobalUses(const Ice::Current &) -{ - return fetchCache<Gentoo::Uses>(sql::portage::getGlobalUses, 30); -} - -Gentoo::Uses -Portage::getGroupUses(const std::string_view group, const Ice::Current &) -{ - return fetchCache<Gentoo::Uses>(sql::portage::getGroupUses, 30, group); -} - -Gentoo::StringList -Portage::getUseGroups(const Ice::Current &) -{ - return fetchCache<Gentoo::StringList>(sql::portage::getUseGroups, 30); -} - -Gentoo::Uses -Portage::getUseUsage(const std::string_view use, const Ice::Current &) -{ - return fetchCache<Gentoo::Uses>(sql::portage::getUseUsage, 30, use, use, use, use); -} - -Gentoo::Packages -Portage::getUsePackages(const std::string_view use, const Ice::Current &) -{ - return fetchCache<Gentoo::Packages>(sql::portage::getUsePackages, 30, use, use); -} - -Gentoo::Uses -Portage::getUsesSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache<Gentoo::Uses>(sql::portage::getUsesSearch, 30, query); -} - -Gentoo::BugPtr -Portage::getBug(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::BugPtr>(sql::portage::getBug, 30, id); -} - -Gentoo::Bugs -Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) -{ - return fetchCache<Gentoo::Bugs>(sql::portage::getPackageBugs, 30, packageId); -} - -Gentoo::SearchResultBugs -Portage::getBugsSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache<Gentoo::SearchResultBugs>(sql::portage::getBugsSearch, 30, query, query); -} - -Gentoo::NewsItemPtr -Portage::getNewsItem(const std::string_view id, const Ice::Current &) -{ - return fetchCache<Gentoo::NewsItemPtr>(sql::portage::getNewsItem, 30, id); -} - -Gentoo::News -Portage::getNewsSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache<Gentoo::News>(sql::portage::getNewsSearch, 30, query); -} - -Gentoo::News -Portage::getNewsRecent(Ice::Int items, const Ice::Current &) -{ - return fetchCache<Gentoo::News>(sql::portage::getNewsRecent, 30, items); -} - -Gentoo::Repository -Portage::getRepository(Ice::Int id, const Ice::Current &) -{ - return fetchCache<Gentoo::Repository>(sql::portage::getRepository, 30, id); -} - -Gentoo::Repositories -Portage::getRepositories(const Ice::Current &) -{ - return fetchCache<Gentoo::Repositories>(sql::portage::getRepositories, 30); -} -} -} - diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index ee72665..77d2e61 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -1,66 +1,68 @@ #ifndef PORTAGEIMPL_H #define PORTAGEIMPL_H +#include <abstractCachingDatabaseClient.h> #include <portage.h> #include <visibility.h> -#include <abstractCachingDatabaseClient.h> namespace Gentoo { -namespace Service { -class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatabaseClient { - public: - Portage(const DB::ConnectionPoolPtr & d); + namespace Service { + class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatabaseClient { + public: + Portage(const DB::ConnectionPoolPtr & d); - Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override; - Gentoo::CategoryPtr findCategory(const std::string_view name, const Ice::Current &) override; - Gentoo::Categories getAllCategories(const Ice::Current &) override; - Gentoo::Categories getCategoriesInSuper(const std::string_view, const Ice::Current &) override; - Gentoo::OverviewCategoriesBySuper getAllOverviewCategories(const Ice::Current &) override; - Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string_view, const Ice::Current &) override; + Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override; + Gentoo::CategoryPtr findCategory(const std::string_view name, const Ice::Current &) override; + Gentoo::Categories getAllCategories(const Ice::Current &) override; + Gentoo::Categories getCategoriesInSuper(const std::string_view, const Ice::Current &) override; + Gentoo::OverviewCategoriesBySuper getAllOverviewCategories(const Ice::Current &) override; + Gentoo::OverviewCategories getOverviewCategoriesInSuper( + const std::string_view, const Ice::Current &) override; - Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; - Gentoo::PackagePtr findPackage(const std::string_view, const std::string_view, const Ice::Current &) override; - Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; - Gentoo::Packages getAllPackages(const Ice::Current &) override; - Gentoo::SearchResultPackages getPackagesSearch(const std::string_view query, const Ice::Current &) override; - Gentoo::Ebuilds getPackageVersions(Ice::Int id, const Ice::Current &) override; - Gentoo::EbuildDetails getPackageVersionDetails(Ice::Int id, const Ice::Current &) override; - Gentoo::ChangeLog getPackageChangeLog(Ice::Int id, const Ice::Current &) override; - Gentoo::Ebuilds getRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; - Gentoo::Packages getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; - Gentoo::Categories getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; - Gentoo::Packages getTopTrackedPackages(Ice::Int n, const Ice::Current &) override; - Gentoo::PackageDependencyPackages getPackageDependencies(Ice::Int id, const Ice::Current &) override; - Gentoo::PackageDependencyPackages getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) override; - Gentoo::PackageDependencyPackages getPackagesDepending(Ice::Int id, const Ice::Current &) override; - Gentoo::PackageMasks getPackageMasks(Ice::Int id, const Ice::Current &) override; - Gentoo::Uses getPackageUses(Ice::Int id, const Ice::Current &) override; - Gentoo::Packages getUserTrackedPackages(Ice::Int userid, const Ice::Current &) override; - Gentoo::Ebuilds getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) override; - Gentoo::StringList getPackageUrls(Ice::Int id, const Ice::Current &) override; - Gentoo::Ebuilds getEbuildsByFilter(const std::string_view, const Ice::Current &) override; + Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; + Gentoo::PackagePtr findPackage( + const std::string_view, const std::string_view, const Ice::Current &) override; + Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; + Gentoo::Packages getAllPackages(const Ice::Current &) override; + Gentoo::SearchResultPackages getPackagesSearch(const std::string_view query, const Ice::Current &) override; + Gentoo::Ebuilds getPackageVersions(Ice::Int id, const Ice::Current &) override; + Gentoo::EbuildDetails getPackageVersionDetails(Ice::Int id, const Ice::Current &) override; + Gentoo::ChangeLog getPackageChangeLog(Ice::Int id, const Ice::Current &) override; + Gentoo::Ebuilds getRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; + Gentoo::Packages getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; + Gentoo::Categories getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) override; + Gentoo::Packages getTopTrackedPackages(Ice::Int n, const Ice::Current &) override; + Gentoo::PackageDependencyPackages getPackageDependencies(Ice::Int id, const Ice::Current &) override; + Gentoo::PackageDependencyPackages getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) override; + Gentoo::PackageDependencyPackages getPackagesDepending(Ice::Int id, const Ice::Current &) override; + Gentoo::PackageMasks getPackageMasks(Ice::Int id, const Ice::Current &) override; + Gentoo::Uses getPackageUses(Ice::Int id, const Ice::Current &) override; + Gentoo::Packages getUserTrackedPackages(Ice::Int userid, const Ice::Current &) override; + Gentoo::Ebuilds getUserTrackedRecentVersions( + Ice::Int userid, Ice::Int limit, const Ice::Current &) override; + Gentoo::StringList getPackageUrls(Ice::Int id, const Ice::Current &) override; + Gentoo::Ebuilds getEbuildsByFilter(const std::string_view, const Ice::Current &) override; - Gentoo::UsePtr getUse(const std::string_view, const Ice::Current &) override; - Gentoo::Uses getGlobalUses(const Ice::Current &) override; - Gentoo::Uses getGroupUses(const std::string_view, const Ice::Current &) override; - Gentoo::StringList getUseGroups(const Ice::Current &) override; - Gentoo::Uses getUseUsage(const std::string_view, const Ice::Current &) override; - Gentoo::Packages getUsePackages(const std::string_view, const Ice::Current &) override; - Gentoo::Uses getUsesSearch(const std::string_view, const Ice::Current &) override; + Gentoo::UsePtr getUse(const std::string_view, const Ice::Current &) override; + Gentoo::Uses getGlobalUses(const Ice::Current &) override; + Gentoo::Uses getGroupUses(const std::string_view, const Ice::Current &) override; + Gentoo::StringList getUseGroups(const Ice::Current &) override; + Gentoo::Uses getUseUsage(const std::string_view, const Ice::Current &) override; + Gentoo::Packages getUsePackages(const std::string_view, const Ice::Current &) override; + Gentoo::Uses getUsesSearch(const std::string_view, const Ice::Current &) override; - Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; - Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; - Gentoo::SearchResultBugs getBugsSearch(const std::string_view query, const Ice::Current &) override; + Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; + Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; + Gentoo::SearchResultBugs getBugsSearch(const std::string_view query, const Ice::Current &) override; - Gentoo::NewsItemPtr getNewsItem(const std::string_view, const Ice::Current &) override; - Gentoo::News getNewsSearch(const std::string_view, const Ice::Current &) override; - Gentoo::News getNewsRecent(Ice::Int, const Ice::Current &) override; + Gentoo::NewsItemPtr getNewsItem(const std::string_view, const Ice::Current &) override; + Gentoo::News getNewsSearch(const std::string_view, const Ice::Current &) override; + Gentoo::News getNewsRecent(Ice::Int, const Ice::Current &) override; - Gentoo::Repository getRepository(Ice::Int, const Ice::Current &) override; - Gentoo::Repositories getRepositories(const Ice::Current &) override; -}; -} + Gentoo::Repository getRepository(Ice::Int, const Ice::Current &) override; + Gentoo::Repositories getRepositories(const Ice::Current &) override; + }; + } } #endif - diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp index 1b74dfd..d62bd7e 100644 --- a/gentoobrowse-api/service/usersimpl.cpp +++ b/gentoobrowse-api/service/usersimpl.cpp @@ -1,140 +1,138 @@ #include "usersimpl.h" -#include <Ice/ObjectAdapter.h> #include <Ice/Communicator.h> +#include <Ice/ObjectAdapter.h> +#include <icecube.h> #include <modifycommand.h> +#include <notifications.h> #include <sql/users/authenticate.sql.h> -#include <sql/users/verify.sql.h> #include <sql/users/create.sql.h> +#include <sql/users/find.sql.h> #include <sql/users/get.sql.h> #include <sql/users/getNew.sql.h> -#include <sql/users/find.sql.h> -#include <sql/users/safeDelete.sql.h> +#include <sql/users/mailshotsent.sql.h> #include <sql/users/prune.sql.h> +#include <sql/users/safeDelete.sql.h> #include <sql/users/track.sql.h> -#include <sql/users/untrack.sql.h> #include <sql/users/tracked.sql.h> -#include <sql/users/mailshotsent.sql.h> -#include <notifications.h> -#include <icecube.h> +#include <sql/users/untrack.sql.h> +#include <sql/users/verify.sql.h> namespace Gentoo { -namespace Service { -Users::Users(const DB::ConnectionPoolPtr & d) : - IceTray::AbstractCachingDatabaseClient(d) -{ -} - -Gentoo::UserPtr -Users::authenticate(const std::string_view username, const std::string_view password, const Ice::Current &) -{ - return fetchCache<Gentoo::UserPtr>(sql::users::authenticate, 30, username, password); -} - -Gentoo::UserPtr -Users::verify(const std::string_view username, const std::string_view verifyguid, const Ice::Current &) -{ - return fetch<Gentoo::UserPtr>(sql::users::verify, username, verifyguid); -} - -Gentoo::UserPtr -Users::get(Ice::Int id, const Ice::Current &) -{ - return fetch<Gentoo::UserPtr>(sql::users::get, id); -} - -Gentoo::NewUserPtr -Users::getNew(const std::string_view username, const std::string_view password, const Ice::Current &) -{ - return fetch<Gentoo::NewUserPtr>(sql::users::getNew, username, password); -} - -Gentoo::UserPtr -Users::find(const std::string_view username, const Ice::Current &) -{ - return fetch<Gentoo::UserPtr>(sql::users::find, username); -} - -Gentoo::NewUserPtr -Users::authOrCreate(const std::string_view & username, const std::string_view & password, const std::string_view & realname, const std::string_view & email) -{ - auto existing = fetch<IceUtil::Optional<Gentoo::NewUserPtr>>(sql::users::getNew, username, password); - if (existing && *existing) { - return *existing; + namespace Service { + Users::Users(const DB::ConnectionPoolPtr & d) : IceTray::AbstractCachingDatabaseClient(d) { } + + Gentoo::UserPtr + Users::authenticate(const std::string_view username, const std::string_view password, const Ice::Current &) + { + return fetchCache<Gentoo::UserPtr>(sql::users::authenticate, 30, username, password); + } + + Gentoo::UserPtr + Users::verify(const std::string_view username, const std::string_view verifyguid, const Ice::Current &) + { + return fetch<Gentoo::UserPtr>(sql::users::verify, username, verifyguid); + } + + Gentoo::UserPtr + Users::get(Ice::Int id, const Ice::Current &) + { + return fetch<Gentoo::UserPtr>(sql::users::get, id); + } + + Gentoo::NewUserPtr + Users::getNew(const std::string_view username, const std::string_view password, const Ice::Current &) + { + return fetch<Gentoo::NewUserPtr>(sql::users::getNew, username, password); + } + + Gentoo::UserPtr + Users::find(const std::string_view username, const Ice::Current &) + { + return fetch<Gentoo::UserPtr>(sql::users::find, username); + } + + Gentoo::NewUserPtr + Users::authOrCreate(const std::string_view & username, const std::string_view & password, + const std::string_view & realname, const std::string_view & email) + { + auto existing = fetch<IceUtil::Optional<Gentoo::NewUserPtr>>(sql::users::getNew, username, password); + if (existing && *existing) { + return *existing; + } + return fetch<Gentoo::NewUserPtr>(sql::users::create, username, password, realname, email); + } + + Gentoo::NewUserPtr + Users::create(const std::string_view username, const std::string_view password, const std::string_view realname, + const std::string_view email, const Ice::Current &) + { + auto notifications = IceTray::Cube::get<Notifications>(); + auto mailServer = IceTray::Cube::get<IceTray::Mail::MailServer>(); + + auto dbc = db->get(); + DB::TransactionScope tx(*dbc.get()); + + auto newUser = authOrCreate(username, password, realname, email); + auto mail = notifications->getSignup(newUser); + mailServer->sendEmail(mail); + + return newUser; + } + + void + Users::mailshotsent(Ice::Int id, const Ice::Current &) + { + auto dbc = db->get(); + auto upd = sql::users::mailshotsent.modify(dbc.get()); + upd->bindParamI(0, id); + upd->execute(); + } + + void + Users::remove(Ice::Int id, const std::string_view password, const Ice::Current &) + { + auto dbc = db->get(); + auto del = sql::users::safeDelete.modify(dbc.get()); + del->bindParamI(0, id); + del->bindParamS(1, password); + del->execute(); + } + + void + Users::prune(const Ice::Current & current) + { + auto properties = current.adapter->getCommunicator()->getProperties(); + auto prunePeriod = properties->getPropertyWithDefault("GentooBrowseAPI.Users.PrunePeriod", "8 weeks"); + auto dbc = db->get(); + auto prune = sql::users::prune.modify(dbc.get()); + prune->bindParamS(0, prunePeriod); + prune->execute(); + } + + void + Users::track(Ice::Int userId, Ice::Int packageId, const Ice::Current &) + { + auto dbc = db->get(); + auto track = sql::users::track.modify(dbc.get()); + track->bindParamI(0, userId); + track->bindParamI(1, packageId); + track->execute(); + } + + void + Users::untrack(Ice::Int userId, Ice::Int packageId, const Ice::Current &) + { + auto dbc = db->get(); + auto untrack = sql::users::untrack.modify(dbc.get()); + untrack->bindParamI(0, userId); + untrack->bindParamI(1, packageId); + untrack->execute(); + } + + Gentoo::PackageIds + Users::tracked(Ice::Int userId, const Ice::Current &) + { + return fetchCache<Gentoo::PackageIds>(sql::users::tracked, 10, userId); + } } - return fetch<Gentoo::NewUserPtr>(sql::users::create, username, password, realname, email); -} - -Gentoo::NewUserPtr -Users::create(const std::string_view username, const std::string_view password, const std::string_view realname, const std::string_view email, const Ice::Current &) -{ - auto notifications = IceTray::Cube::get<Notifications>(); - auto mailServer = IceTray::Cube::get<IceTray::Mail::MailServer>(); - - auto dbc = db->get(); - DB::TransactionScope tx(*dbc.get()); - - auto newUser = authOrCreate(username, password, realname, email); - auto mail = notifications->getSignup(newUser); - mailServer->sendEmail(mail); - - return newUser; -} - -void -Users::mailshotsent(Ice::Int id, const Ice::Current &) -{ - auto dbc = db->get(); - auto upd = sql::users::mailshotsent.modify(dbc.get()); - upd->bindParamI(0, id); - upd->execute(); -} - -void -Users::remove(Ice::Int id, const std::string_view password, const Ice::Current &) -{ - auto dbc = db->get(); - auto del = sql::users::safeDelete.modify(dbc.get()); - del->bindParamI(0, id); - del->bindParamS(1, password); - del->execute(); -} - -void -Users::prune(const Ice::Current & current) -{ - auto properties = current.adapter->getCommunicator()->getProperties(); - auto prunePeriod = properties->getPropertyWithDefault("GentooBrowseAPI.Users.PrunePeriod", "8 weeks"); - auto dbc = db->get(); - auto prune = sql::users::prune.modify(dbc.get()); - prune->bindParamS(0, prunePeriod); - prune->execute(); -} - -void -Users::track(Ice::Int userId, Ice::Int packageId, const Ice::Current &) -{ - auto dbc = db->get(); - auto track = sql::users::track.modify(dbc.get()); - track->bindParamI(0, userId); - track->bindParamI(1, packageId); - track->execute(); -} - -void -Users::untrack(Ice::Int userId, Ice::Int packageId, const Ice::Current &) -{ - auto dbc = db->get(); - auto untrack = sql::users::untrack.modify(dbc.get()); - untrack->bindParamI(0, userId); - untrack->bindParamI(1, packageId); - untrack->execute(); -} - -Gentoo::PackageIds -Users::tracked(Ice::Int userId, const Ice::Current &) -{ - return fetchCache<Gentoo::PackageIds>(sql::users::tracked, 10, userId); } -} -} - diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h index e85c305..79c5623 100644 --- a/gentoobrowse-api/service/usersimpl.h +++ b/gentoobrowse-api/service/usersimpl.h @@ -1,36 +1,37 @@ #ifndef USERSIMPL_H #define USERSIMPL_H +#include <abstractCachingDatabaseClient.h> #include <users.h> #include <visibility.h> -#include <abstractCachingDatabaseClient.h> namespace Gentoo { -namespace Service { -class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseClient { - public: - Users(const DB::ConnectionPoolPtr & d); - - Gentoo::UserPtr authenticate(const std::string_view, const std::string_view, const Ice::Current &) override; - Gentoo::UserPtr verify(const std::string_view, const std::string_view, const Ice::Current &) override; - - Gentoo::UserPtr get(Ice::Int id, const Ice::Current &) override; - Gentoo::NewUserPtr getNew(const std::string_view, const std::string_view, const Ice::Current &) override; - Gentoo::UserPtr find(const std::string_view username, const Ice::Current &) override; - Gentoo::NewUserPtr create(const std::string_view, const std::string_view, const std::string_view, const std::string_view, const Ice::Current &) override; - void mailshotsent(Ice::Int id, const Ice::Current &) override; - void remove(Ice::Int id, const std::string_view, const Ice::Current &) override; - void prune(const Ice::Current &) override; - - void track(Ice::Int, Ice::Int, const Ice::Current &) override; - void untrack(Ice::Int, Ice::Int, const Ice::Current &) override; - Gentoo::PackageIds tracked(Ice::Int, const Ice::Current &) override; - - private: - DLL_PRIVATE Gentoo::NewUserPtr authOrCreate(const std::string_view &, const std::string_view &, const std::string_view &, const std::string_view &); -}; -} + namespace Service { + class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseClient { + public: + Users(const DB::ConnectionPoolPtr & d); + + Gentoo::UserPtr authenticate(const std::string_view, const std::string_view, const Ice::Current &) override; + Gentoo::UserPtr verify(const std::string_view, const std::string_view, const Ice::Current &) override; + + Gentoo::UserPtr get(Ice::Int id, const Ice::Current &) override; + Gentoo::NewUserPtr getNew(const std::string_view, const std::string_view, const Ice::Current &) override; + Gentoo::UserPtr find(const std::string_view username, const Ice::Current &) override; + Gentoo::NewUserPtr create(const std::string_view, const std::string_view, const std::string_view, + const std::string_view, const Ice::Current &) override; + void mailshotsent(Ice::Int id, const Ice::Current &) override; + void remove(Ice::Int id, const std::string_view, const Ice::Current &) override; + void prune(const Ice::Current &) override; + + void track(Ice::Int, Ice::Int, const Ice::Current &) override; + void untrack(Ice::Int, Ice::Int, const Ice::Current &) override; + Gentoo::PackageIds tracked(Ice::Int, const Ice::Current &) override; + + private: + DLL_PRIVATE Gentoo::NewUserPtr authOrCreate(const std::string_view &, const std::string_view &, + const std::string_view &, const std::string_view &); + }; + } } #endif - diff --git a/gentoobrowse-api/service/utils/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp index 3e70281..c281265 100644 --- a/gentoobrowse-api/service/utils/dbUtils.cpp +++ b/gentoobrowse-api/service/utils/dbUtils.cpp @@ -1,9 +1,9 @@ #include "dbUtils.h" -#include <boost/lexical_cast.hpp> +#include <atomic> #include <boost/algorithm/string/join.hpp> -#include <tablepatch.h> +#include <boost/lexical_cast.hpp> #include <buffer.h> -#include <atomic> +#include <tablepatch.h> namespace Gentoo { namespace Utils { @@ -22,7 +22,8 @@ namespace Gentoo { } std::pair<std::string, DB::ModifyCommandPtr> - namedTemp(DB::Connection * db, const std::string & tempTable, const std::map<std::string, const std::string> & cols) + namedTemp(DB::Connection * db, const std::string & tempTable, + const std::map<std::string, const std::string> & cols) { std::set<std::string> keys; std::set<std::string> defs; @@ -30,9 +31,8 @@ namespace Gentoo { keys.insert(c.first); defs.insert(c.first + " " + c.second); } - db->execute("CREATE TEMPORARY TABLE " + tempTable + "(" + - boost::join(defs, ",") + ")"); - return { tempTable, tablePatchInserter(db, tempTable, keys) }; + db->execute("CREATE TEMPORARY TABLE " + tempTable + "(" + boost::join(defs, ",") + ")"); + return {tempTable, tablePatchInserter(db, tempTable, keys)}; } void @@ -49,12 +49,9 @@ namespace Gentoo { DB::ModifyCommandPtr tablePatchInserter(DB::Connection * dbc, const std::string & t, const std::set<std::string> & c) { - return dbc->modify( - "INSERT INTO " + t + - "(" + boost::algorithm::join(c, ", ") + - ") VALUES(" + boost::algorithm::join(std::vector<std::string>(c.size(), "?"), ", ") + ")"); + return dbc->modify("INSERT INTO " + t + "(" + boost::algorithm::join(c, ", ") + ") VALUES(" + + boost::algorithm::join(std::vector<std::string>(c.size(), "?"), ", ") + ")"); } } } } - diff --git a/gentoobrowse-api/service/utils/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h index cbb8292..cdd9c07 100644 --- a/gentoobrowse-api/service/utils/dbUtils.h +++ b/gentoobrowse-api/service/utils/dbUtils.h @@ -1,23 +1,24 @@ #ifndef GENTOOBROWSE_API_SERVICE_DBUTILS_H #define GENTOOBROWSE_API_SERVICE_DBUTILS_H -#include <command.h> -#include <modifycommand.h> -#include <connection.h> #include <IceUtil/Exception.h> #include <IceUtil/Optional.h> +#include <command.h> +#include <connection.h> +#include <modifycommand.h> namespace Gentoo { namespace Utils { namespace Database { std::string emptyClone(DB::Connection *, const std::string &); - std::pair<std::string, DB::ModifyCommandPtr> namedTemp(DB::Connection *, const std::string &, const std::map<std::string, const std::string> & cols); + std::pair<std::string, DB::ModifyCommandPtr> namedTemp( + DB::Connection *, const std::string &, const std::map<std::string, const std::string> & cols); void drop(DB::Connection *, const std::string &); DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const DB::TablePatch &); - DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const std::string &, const std::set<std::string> &); + DB::ModifyCommandPtr tablePatchInserter( + DB::Connection *, const std::string &, const std::set<std::string> &); } } } #endif - diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp index bbe804e..cd50d1a 100644 --- a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp +++ b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp @@ -2,13 +2,12 @@ namespace Gentoo { namespace Utils { - EbuildCacheParser::EbuildCacheParser(const std::filesystem::path & p) : - AdHoc::FileUtils::MemMap(p) + EbuildCacheParser::EbuildCacheParser(const std::filesystem::path & p) : AdHoc::FileUtils::MemMap(p) { auto chardata = sv(); for (auto eq = chardata.find('='); eq != std::string_view::npos; eq = chardata.find('=')) { if (auto nl = chardata.find('\n', eq + 1); nl != std::string_view::npos) { - kvs.insert({ chardata.substr(0, eq), chardata.substr(eq + 1, nl - eq - 1) }); + kvs.insert({chardata.substr(0, eq), chardata.substr(eq + 1, nl - eq - 1)}); chardata.remove_prefix(nl + 1); } } @@ -35,4 +34,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.h b/gentoobrowse-api/service/utils/ebuildCacheParser.h index 6874d40..1573439 100644 --- a/gentoobrowse-api/service/utils/ebuildCacheParser.h +++ b/gentoobrowse-api/service/utils/ebuildCacheParser.h @@ -2,28 +2,27 @@ #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H #include <fileUtils.h> -#include <map> -#include <string_view> -#include <optional> #include <filesystem> #include <glibmm/ustring.h> +#include <map> +#include <optional> +#include <string_view> namespace Gentoo { namespace Utils { class EbuildCacheParser : public AdHoc::FileUtils::MemMap { - public: - typedef std::map<std::string_view, const std::string_view> KVs; + public: + typedef std::map<std::string_view, const std::string_view> KVs; - EbuildCacheParser(const std::filesystem::path & p); + EbuildCacheParser(const std::filesystem::path & p); - std::optional<Glib::ustring> get(const std::string & key) const; - std::optional<std::string_view> getRange(const std::string & key) const; + std::optional<Glib::ustring> get(const std::string & key) const; + std::optional<std::string_view> getRange(const std::string & key) const; - private: - KVs kvs; + private: + KVs kvs; }; } } #endif - diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.cpp b/gentoobrowse-api/service/utils/entityWhereFilter.cpp index 2588edd..93a36aa 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.cpp +++ b/gentoobrowse-api/service/utils/entityWhereFilter.cpp @@ -3,23 +3,17 @@ namespace Gentoo { namespace Utils { - template<typename T> - EntityWhereFilter<T>::EntityWhereFilter(const std::string & en) : - entityColName(en) - { - } + template<typename T> EntityWhereFilter<T>::EntityWhereFilter(const std::string & en) : entityColName(en) { } template<typename T> - EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const T & e) : - entityColName(en) + EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const T & e) : entityColName(en) { entityIds.insert(e); } template<typename T> EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const EntityIds & e) : - entityIds(e), - entityColName(en) + entityIds(e), entityColName(en) { } @@ -61,4 +55,3 @@ namespace Gentoo { template class EntityWhereFilter<std::string>; } } - diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.h b/gentoobrowse-api/service/utils/entityWhereFilter.h index 94e286d..805e033 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.h +++ b/gentoobrowse-api/service/utils/entityWhereFilter.h @@ -1,28 +1,26 @@ #ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H -#include <sqlWriter.h> #include <set> +#include <sqlWriter.h> namespace Gentoo { namespace Utils { - template<typename T> - class EntityWhereFilter : public DB::SqlWriter { - public: - typedef std::set<T> EntityIds; + template<typename T> class EntityWhereFilter : public DB::SqlWriter { + public: + typedef std::set<T> EntityIds; - EntityWhereFilter(const std::string & en); - EntityWhereFilter(const std::string & en, const T & e); - EntityWhereFilter(const std::string & en, const EntityIds & e); + EntityWhereFilter(const std::string & en); + EntityWhereFilter(const std::string & en, const T & e); + EntityWhereFilter(const std::string & en, const EntityIds & e); - void writeSql(AdHoc::Buffer & sql) override; - void bindParams(DB::Command * c, unsigned int & offset) override; + void writeSql(AdHoc::Buffer & sql) override; + void bindParams(DB::Command * c, unsigned int & offset) override; - EntityIds entityIds; - const std::string entityColName; + EntityIds entityIds; + const std::string entityColName; }; } } #endif - diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp index 450bfec..1d7d9a8 100644 --- a/gentoobrowse-api/service/utils/git.cpp +++ b/gentoobrowse-api/service/utils/git.cpp @@ -1,8 +1,8 @@ #include "git.h" -#include <maintenance.h> -#include <execinfo.h> #include <compileTimeFormatter.h> +#include <execinfo.h> #include <logger.h> +#include <maintenance.h> namespace Gentoo { namespace Utils { @@ -41,8 +41,8 @@ namespace Gentoo { auto localBranch = gitSafeGet(git_repository_head, git_reference_free, repo); auto localBranchName = gitSafeGet(git_branch_name, localBranch.get()); auto refspec = RefSpec::get(localBranchName, git_remote_name(remote), remoteBranchName); - char * s[] = { &refspec.front() }; - git_strarray refs = { s, 1 }; + char * s[] = {&refspec.front()}; + git_strarray refs = {s, 1}; gitSafe(git_remote_fetch, remote, &refs, &opts, nullptr); return gitSafeGet(git_annotated_commit_from_revspec, git_annotated_commit_free, repo, "FETCH_HEAD"); } @@ -54,7 +54,7 @@ namespace Gentoo { { auto log = LOGMANAGER()->getLogger(__FUNCTION__); // Test fast-forward is possible - const git_annotated_commit * heads[] = { fetch_head }; + const git_annotated_commit * heads[] = {fetch_head}; git_merge_analysis_t analysis = GIT_MERGE_ANALYSIS_NONE; git_merge_preference_t preference = GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY; gitSafe(git_merge_analysis, &analysis, &preference, repo, heads, 1); @@ -69,8 +69,10 @@ namespace Gentoo { // Perform fast-forward auto fetch_head_id = *git_annotated_commit_id(fetch_head); - auto fetch_head_object = gitSafeGet(git_object_lookup, git_object_free, repo, &fetch_head_id, GIT_OBJ_ANY); - log->messagectf<FastForward>(IceTray::Logging::LogLevel::INFO, *git_reference_target(head.get()), fetch_head_id); + auto fetch_head_object + = gitSafeGet(git_object_lookup, git_object_free, repo, &fetch_head_id, GIT_OBJ_ANY); + log->messagectf<FastForward>( + IceTray::Logging::LogLevel::INFO, *git_reference_target(head.get()), fetch_head_id); gitSafeGet(git_reference_set_target, git_reference_free, head.get(), &fetch_head_id, "fast-forward"); // Checkout new head @@ -108,4 +110,3 @@ namespace std { return s; } } - diff --git a/gentoobrowse-api/service/utils/git.h b/gentoobrowse-api/service/utils/git.h index 20e8755..7e2e66a 100644 --- a/gentoobrowse-api/service/utils/git.h +++ b/gentoobrowse-api/service/utils/git.h @@ -1,8 +1,8 @@ #ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H -#include <memory> #include <git2.h> +#include <memory> #include <ostream> namespace Gentoo { @@ -10,30 +10,29 @@ namespace Gentoo { namespace Git { void throwError(void * const func, int err); - template<typename ... P, typename ... A> + template<typename... P, typename... A> void - gitSafe(int (*func)(P...), A ... p) + gitSafe(int (*func)(P...), A... p) { if (int _giterror = func(p...) < 0) { throwError((void * const)func, _giterror); } } - template<typename T> - using GitTPtr = std::unique_ptr<T, void(*)(T*)>; + template<typename T> using GitTPtr = std::unique_ptr<T, void (*)(T *)>; - template<typename R, typename ... P, typename ... A> + template<typename R, typename... P, typename... A> GitTPtr<R> - gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p) + gitSafeGet(int (*get)(R **, P...), void (*release)(R *), A... p) { R * r = nullptr; gitSafe(get, &r, p...); return GitTPtr<R>(r, release); } - template<typename R, typename ... P, typename ... A> + template<typename R, typename... P, typename... A> R - gitSafeGet(int(*get)(R*, P...), A ... p) + gitSafeGet(int (*get)(R *, P...), A... p) { R r; gitSafe(get, &r, p...); @@ -43,14 +42,11 @@ namespace Gentoo { std::string operator*(const git_oid &); using GitAnnotatedCommitPtr = GitTPtr<git_annotated_commit>; - GitAnnotatedCommitPtr - gitFetch(git_repository * repo, git_remote * remote, const char * branch); + GitAnnotatedCommitPtr gitFetch(git_repository * repo, git_remote * remote, const char * branch); - git_oid - gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head); + git_oid gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head); - void - updateRepository(const std::string & path, const std::string & upstream, const std::string & branch); + void updateRepository(const std::string & path, const std::string & upstream, const std::string & branch); } } } @@ -60,4 +56,3 @@ namespace std { } #endif - diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.cpp b/gentoobrowse-api/service/utils/splitEbuildProps.cpp index ce052ab..3d6b6e8 100644 --- a/gentoobrowse-api/service/utils/splitEbuildProps.cpp +++ b/gentoobrowse-api/service/utils/splitEbuildProps.cpp @@ -1,21 +1,21 @@ #include "splitEbuildProps.h" -#include <command.h> #include "dbUtils.h" +#include <command.h> namespace Gentoo { namespace Utils { - SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & p) : + SplitEbuildProps::SplitEbuildProps( + const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & p) : entityId(e), - colEntityName(ce), - colPropName(cp), - props(p) + colEntityName(ce), colPropName(cp), props(p) { } void SplitEbuildProps::writeSql(AdHoc::Buffer & sql) { - sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName, colPropName); + sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName, + colPropName); } void @@ -26,4 +26,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.h b/gentoobrowse-api/service/utils/splitEbuildProps.h index c6ed14f..00ce910 100644 --- a/gentoobrowse-api/service/utils/splitEbuildProps.h +++ b/gentoobrowse-api/service/utils/splitEbuildProps.h @@ -1,25 +1,25 @@ #ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H #define GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H -#include <sqlWriter.h> #include <glibmm/ustring.h> #include <optional> +#include <sqlWriter.h> namespace Gentoo { namespace Utils { class SplitEbuildProps : public DB::SqlWriter { - public: - SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & p); + public: + SplitEbuildProps( + const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & p); - void writeSql(AdHoc::Buffer & sql) override; - void bindParams(DB::Command * c, unsigned int & offset) override; + void writeSql(AdHoc::Buffer & sql) override; + void bindParams(DB::Command * c, unsigned int & offset) override; - const int entityId; - const std::string colEntityName, colPropName; - const std::optional<Glib::ustring> props; + const int entityId; + const std::string colEntityName, colPropName; + const std::optional<Glib::ustring> props; }; } } #endif - diff --git a/gentoobrowse-api/service/utils/xmlUtils.cpp b/gentoobrowse-api/service/utils/xmlUtils.cpp index f938efa..1ddc16e 100644 --- a/gentoobrowse-api/service/utils/xmlUtils.cpp +++ b/gentoobrowse-api/service/utils/xmlUtils.cpp @@ -2,10 +2,7 @@ namespace Gentoo { namespace Utils { - XmlDoc::XmlDoc(const std::filesystem::path & path) : - xmlpp::DomParser(path) - { - } + XmlDoc::XmlDoc(const std::filesystem::path & path) : xmlpp::DomParser(path) { } std::optional<Glib::ustring> XmlDoc::getXPathValue(const Glib::ustring & xp) @@ -23,4 +20,3 @@ namespace Gentoo { } } } - diff --git a/gentoobrowse-api/service/utils/xmlUtils.h b/gentoobrowse-api/service/utils/xmlUtils.h index 3e71f1d..82584cc 100644 --- a/gentoobrowse-api/service/utils/xmlUtils.h +++ b/gentoobrowse-api/service/utils/xmlUtils.h @@ -1,20 +1,19 @@ #ifndef GENTOOBROWSE_API_SERVICE_XMLUTILS_H #define GENTOOBROWSE_API_SERVICE_XMLUTILS_H -#include <libxml++/parsers/domparser.h> #include <filesystem> +#include <libxml++/parsers/domparser.h> #include <optional> namespace Gentoo { namespace Utils { class XmlDoc : public xmlpp::DomParser { - public: - XmlDoc(const std::filesystem::path &); + public: + XmlDoc(const std::filesystem::path &); - std::optional<Glib::ustring> getXPathValue(const Glib::ustring &); + std::optional<Glib::ustring> getXPathValue(const Glib::ustring &); }; } } #endif - diff --git a/gentoobrowse-api/service/xsltStreamSerializer.cpp b/gentoobrowse-api/service/xsltStreamSerializer.cpp index 7df6f00..bbffeba 100644 --- a/gentoobrowse-api/service/xsltStreamSerializer.cpp +++ b/gentoobrowse-api/service/xsltStreamSerializer.cpp @@ -1,33 +1,32 @@ #include "xsltStreamSerializer.h" -#include <libxslt/xsltInternals.h> -#include <libxml/HTMLtree.h> #include <factory.impl.h> -#include <processPipes.h> -#include <sys/wait.h> +#include <libxml/HTMLtree.h> +#include <libxslt/xsltInternals.h> #include <mimeImpl.h> #include <notifications/css/style.h> +#include <processPipes.h> +#include <sys/wait.h> namespace Gentoo { using namespace IceTray::Mime; static const std::string css(style_css, style_css + style_css_len); - static int xmlstrmclosecallback(void * context) + static int + xmlstrmclosecallback(void * context) { - ((std::ostream*)context)->flush(); + ((std::ostream *)context)->flush(); return 0; } - static int xmlstrmwritecallback(void * context, const char * buffer, int len) + static int + xmlstrmwritecallback(void * context, const char * buffer, int len) { - ((std::ostream*)context)->write(buffer, len); + ((std::ostream *)context)->write(buffer, len); return len; } XsltStreamSerializer::XsltStreamSerializer(const IceTray::Mail::EmailPtr & e, xsltStylesheet * ss) : - Slicer::XmlDocumentSerializer(doc), - mail(e), - doc(nullptr), - stylesheet(ss) + Slicer::XmlDocumentSerializer(doc), mail(e), doc(nullptr), stylesheet(ss) { } @@ -44,26 +43,30 @@ namespace Gentoo { if (!result) { throw xmlpp::exception("Failed to apply XSL transform"); } - mail->content = std::make_shared<MultiPart>(Headers {}, "alternative", Parts { - getText(result.get()), getHtml(result.get()) - }); + mail->content = std::make_shared<MultiPart>( + Headers {}, "alternative", Parts {getText(result.get()), getHtml(result.get())}); } - IceTray::Mime::BasicPartPtr XsltStreamSerializer::getHtml(xmlDoc * result) + IceTray::Mime::BasicPartPtr + XsltStreamSerializer::getHtml(xmlDoc * result) { std::stringstream strm; xmlOutputBufferPtr buf = xmlOutputBufferCreateIO(xmlstrmwritecallback, xmlstrmclosecallback, &strm, NULL); htmlDocContentDumpFormatOutput(buf, result, "utf-8", 0); xmlOutputBufferClose(buf); - return std::make_shared<MultiPart>(Headers {}, "related", Parts { - std::make_shared<TextPart>(Headers {}, "text/html", strm.str()), - std::make_shared<TextPart>(Headers { - { "Content-Id", "<style.css@gentoobrowse.randomdan.homeip.net>" }, - }, "text/css", css), - }); + return std::make_shared<MultiPart>(Headers {}, "related", + Parts { + std::make_shared<TextPart>(Headers {}, "text/html", strm.str()), + std::make_shared<TextPart>( + Headers { + {"Content-Id", "<style.css@gentoobrowse.randomdan.homeip.net>"}, + }, + "text/css", css), + }); } - IceTray::Mime::BasicPartPtr XsltStreamSerializer::getText(xmlDoc * result) + IceTray::Mime::BasicPartPtr + XsltStreamSerializer::getText(xmlDoc * result) { std::stringstream strm; std::vector<std::string> callLynx; @@ -90,4 +93,3 @@ namespace Gentoo { return std::make_shared<TextPart>(Headers {}, "text/plain", strm.str()); } } - diff --git a/gentoobrowse-api/service/xsltStreamSerializer.h b/gentoobrowse-api/service/xsltStreamSerializer.h index 20c3c05..5e73d59 100644 --- a/gentoobrowse-api/service/xsltStreamSerializer.h +++ b/gentoobrowse-api/service/xsltStreamSerializer.h @@ -1,28 +1,27 @@ #ifndef ICESPIDER_CORE_XSLTSTREAMSERIALIZER_H #define ICESPIDER_CORE_XSLTSTREAMSERIALIZER_H -#include <slicer/xml/serializer.h> -#include <visibility.h> #include <libxslt/transform.h> #include <notifications.h> +#include <slicer/xml/serializer.h> +#include <visibility.h> namespace Gentoo { class DLL_PUBLIC XsltStreamSerializer : public Slicer::XmlDocumentSerializer { - public: - XsltStreamSerializer(const IceTray::Mail::EmailPtr &, xsltStylesheet *); - ~XsltStreamSerializer(); + public: + XsltStreamSerializer(const IceTray::Mail::EmailPtr &, xsltStylesheet *); + ~XsltStreamSerializer(); - void Serialize(Slicer::ModelPartForRootPtr mp) override; + void Serialize(Slicer::ModelPartForRootPtr mp) override; - protected: - static IceTray::Mime::BasicPartPtr getHtml(xmlDoc *); - static IceTray::Mime::BasicPartPtr getText(xmlDoc *); + protected: + static IceTray::Mime::BasicPartPtr getHtml(xmlDoc *); + static IceTray::Mime::BasicPartPtr getText(xmlDoc *); - IceTray::Mail::EmailPtr mail; - xmlpp::Document * doc; - xsltStylesheet * stylesheet; + IceTray::Mail::EmailPtr mail; + xmlpp::Document * doc; + xsltStylesheet * stylesheet; }; } #endif - diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp index 485426b..398e3e9 100644 --- a/gentoobrowse-api/unittests/mockDefs.cpp +++ b/gentoobrowse-api/unittests/mockDefs.cpp @@ -1,29 +1,24 @@ #include "mockDefs.h" #include <definedDirs.h> -#include <notifications.h> -#include <tidy.h> #include <fstream> -#include <mockMailServer.h> #include <icecube.h> +#include <mockMailServer.h> +#include <notifications.h> +#include <tidy.h> Service::Service() : - DB::PluginMock<PQ::Mock>("GentooBrowseAPI", { - rootDir.parent_path() / "db" / "schema.sql", - rootDir / "data.sql" }, + DB::PluginMock<PQ::Mock>("GentooBrowseAPI", {rootDir.parent_path() / "db" / "schema.sql", rootDir / "data.sql"}, "user=postgres dbname=postgres") { IceTray::DryIce::replace<IceTray::Mail::MailServer, IceTray::Mail::MockMailServerImpl>(); } Maintenance::Maintenance() : - IceTray::DryIce({ - "--GentooBrowseAPI.RefreshTarget.gentoo=40539afe6705aee26a55bb861f5e892ae7240057", + IceTray::DryIce({"--GentooBrowseAPI.RefreshTarget.gentoo=40539afe6705aee26a55bb861f5e892ae7240057", "--GentooBrowseAPI.RepoRoot=" + (rootDir / "fixtures" / "gitrepo").string(), - "--GentooBrowseAPI.BugRoot=file://" + (rootDir / "fixtures" / "bugs").string() - }), - DB::PluginMock<PQ::Mock>("GentooBrowseAPI", { - rootDir.parent_path() / "db" / "schema.sql" }, - "user=postgres dbname=postgres") + "--GentooBrowseAPI.BugRoot=file://" + (rootDir / "fixtures" / "bugs").string()}), + DB::PluginMock<PQ::Mock>( + "GentooBrowseAPI", {rootDir.parent_path() / "db" / "schema.sql"}, "user=postgres dbname=postgres") { IceTray::DryIce::replace<IceTray::Mail::MailServer, IceTray::Mail::MockMailServerImpl>(); } @@ -31,15 +26,13 @@ Maintenance::Maintenance() : Mail::Mail() : IceTray::DryIce({ "--GentooBrowseAPI.MailServer=smtp.random.lan:25", - }) + }) { } TestClient::TestClient() : - m(IceTray::Cube::get<Gentoo::Maintenance>()), - p(IceTray::Cube::get<Gentoo::Portage>()), - n(IceTray::Cube::get<Gentoo::Notifications>()), - ms(IceTray::Cube::get<IceTray::Mail::MailServer>()), + m(IceTray::Cube::get<Gentoo::Maintenance>()), p(IceTray::Cube::get<Gentoo::Portage>()), + n(IceTray::Cube::get<Gentoo::Notifications>()), ms(IceTray::Cube::get<IceTray::Mail::MailServer>()), u(IceTray::Cube::get<Gentoo::Users>()) { BOOST_REQUIRE(m); @@ -68,13 +61,13 @@ TestClient::humanReadableParts(IceTray::Mail::EmailPtr e) auto htmlPart = std::dynamic_pointer_cast<IceTray::Mime::TextPart>(htmlRel->parts[0]); BOOST_REQUIRE(htmlPart); - return { plainPart.get(), htmlPart.get() }; + return {plainPart.get(), htmlPart.get()}; } void TestClient::lintable_test_files(std::string_view name, IceTray::Mail::EmailPtr e) { - auto [ plainPart, htmlPart ] = humanReadableParts(e); + auto [plainPart, htmlPart] = humanReadableParts(e); std::ofstream text((binDir / name).replace_extension("txt")); text << plainPart->payload; @@ -94,7 +87,6 @@ TestClient::lintable_test_files(std::string_view name, IceTray::Mail::EmailPtr e fputs("From: dan@randomdan.homeip.net\r\n", eml); fputs("Return-path: <dan@randomdan.homeip.net>\r\n", eml); fputs("Date: Tue, 7 May 2019 19:50:44 +0100\r\n", eml); - e->content->write({ eml }, 0); + e->content->write({eml}, 0); fclose(eml); } - diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h index ee53b0a..7600e15 100644 --- a/gentoobrowse-api/unittests/mockDefs.h +++ b/gentoobrowse-api/unittests/mockDefs.h @@ -1,52 +1,56 @@ #ifndef MOCKDEFS_H #define MOCKDEFS_H -#include <pq-mock.h> -#include <visibility.h> +#include <boost/test/unit_test.hpp> #include <dryice.h> -#include <portage.h> -#include <users.h> #include <maintenance.h> +#include <mimeImpl.h> #include <notifications.h> +#include <portage.h> +#include <pq-mock.h> #include <selectcommandUtil.impl.h> -#include <boost/test/unit_test.hpp> -#include <mimeImpl.h> +#include <users.h> +#include <visibility.h> class DLL_PUBLIC Service : public IceTray::DryIce, DB::PluginMock<PQ::Mock> { - public: - Service(); +public: + Service(); }; class DLL_PUBLIC Maintenance : public IceTray::DryIce, DB::PluginMock<PQ::Mock> { - public: - Maintenance(); +public: + Maintenance(); }; class DLL_PUBLIC Mail : public IceTray::DryIce { - public: - Mail(); +public: + Mail(); }; class DLL_PUBLIC TestClient : public IceTray::DryIceClient { - public: - TestClient(); - - Gentoo::MaintenancePrxPtr m; - Gentoo::PortagePrxPtr p; - Gentoo::NotificationsPtr n; - IceTray::Mail::MailServerPtr ms; - Gentoo::UsersPrxPtr u; - - void lintable_test_files(std::string_view name, IceTray::Mail::EmailPtr e); - std::pair<IceTray::Mime::TextPart *, IceTray::Mime::TextPart *> - humanReadableParts(IceTray::Mail::EmailPtr e); +public: + TestClient(); + + Gentoo::MaintenancePrxPtr m; + Gentoo::PortagePrxPtr p; + Gentoo::NotificationsPtr n; + IceTray::Mail::MailServerPtr ms; + Gentoo::UsersPrxPtr u; + + void lintable_test_files(std::string_view name, IceTray::Mail::EmailPtr e); + std::pair<IceTray::Mime::TextPart *, IceTray::Mime::TextPart *> humanReadableParts(IceTray::Mail::EmailPtr e); }; -#define SQL_REQUIRE_EQUAL(sql, type, expected) BOOST_TEST_CONTEXT(sql) { sqlRequireEqual<type>(db, sql, expected); } +#define SQL_REQUIRE_EQUAL(sql, type, expected) \ + BOOST_TEST_CONTEXT(sql) { \ + sqlRequireEqual<type>(db, sql, expected); \ + } template<typename T> -void sqlRequireEqual(DB::ConnectionPtr db, const char * const sql, const T & expected) { +void +sqlRequireEqual(DB::ConnectionPtr db, const char * const sql, const T & expected) +{ int assertedRows = 0; - db->select(sql)->forEachRow<T>([expected,&assertedRows](const auto & n) { + db->select(sql)->forEachRow<T>([expected, &assertedRows](const auto & n) { BOOST_REQUIRE_EQUAL(expected, n); assertedRows += 1; }); @@ -54,4 +58,3 @@ void sqlRequireEqual(DB::ConnectionPtr db, const char * const sql, const T & exp } #endif - diff --git a/gentoobrowse-api/unittests/testBugs.cpp b/gentoobrowse-api/unittests/testBugs.cpp index d29a6af..175a800 100644 --- a/gentoobrowse-api/unittests/testBugs.cpp +++ b/gentoobrowse-api/unittests/testBugs.cpp @@ -3,11 +3,11 @@ #include "mockDefs.h" -BOOST_GLOBAL_FIXTURE( Maintenance ); +BOOST_GLOBAL_FIXTURE(Maintenance); BOOST_FIXTURE_TEST_SUITE(tp, TestClient) -BOOST_AUTO_TEST_CASE( importBugHtml ) +BOOST_AUTO_TEST_CASE(importBugHtml) { const int64_t expectedBugCount = 34; m->refreshBugs(); @@ -20,4 +20,3 @@ BOOST_AUTO_TEST_CASE( importBugHtml ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/gentoobrowse-api/unittests/testDepend.cpp b/gentoobrowse-api/unittests/testDepend.cpp index e7c232d..73cf3bc 100644 --- a/gentoobrowse-api/unittests/testDepend.cpp +++ b/gentoobrowse-api/unittests/testDepend.cpp @@ -3,7 +3,7 @@ #include <depend.h> -BOOST_AUTO_TEST_CASE( simple1 ) +BOOST_AUTO_TEST_CASE(simple1) { auto ds = Portage::Utils::Depend::parse("sys-libs/readline"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -16,7 +16,7 @@ BOOST_AUTO_TEST_CASE( simple1 ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( simple2 ) +BOOST_AUTO_TEST_CASE(simple2) { auto ds = Portage::Utils::Depend::parse("sys-libs/readline sys-apps/portage"); BOOST_REQUIRE_EQUAL(ds.size(), 2); @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( simple2 ) BOOST_REQUIRE(ds[1]->use.empty()); } -BOOST_AUTO_TEST_CASE( simple2when1 ) +BOOST_AUTO_TEST_CASE(simple2when1) { auto ds = Portage::Utils::Depend::parse("sys-libs/readline !maybe? ( sys-apps/portage ) other/package"); BOOST_REQUIRE_EQUAL(ds.size(), 3); @@ -61,9 +61,10 @@ BOOST_AUTO_TEST_CASE( simple2when1 ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( simple2when2 ) +BOOST_AUTO_TEST_CASE(simple2when2) { - auto ds = Portage::Utils::Depend::parse("sys-libs/readline !maybe? ( and? ( sys-apps/portage ) not/this ) other/package"); + auto ds = Portage::Utils::Depend::parse( + "sys-libs/readline !maybe? ( and? ( sys-apps/portage ) not/this ) other/package"); BOOST_REQUIRE_EQUAL(ds.size(), 4); BOOST_REQUIRE(!ds[0]->op); BOOST_REQUIRE_EQUAL(ds[0]->category, "sys-libs"); @@ -89,7 +90,7 @@ BOOST_AUTO_TEST_CASE( simple2when2 ) BOOST_REQUIRE(ds[3]->when.empty()); } -BOOST_AUTO_TEST_CASE( op ) +BOOST_AUTO_TEST_CASE(op) { auto ds = Portage::Utils::Depend::parse(" !sys-libs/readline "); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -101,7 +102,7 @@ BOOST_AUTO_TEST_CASE( op ) BOOST_REQUIRE(ds[0]->when.empty()); } -BOOST_AUTO_TEST_CASE( version1 ) +BOOST_AUTO_TEST_CASE(version1) { auto ds = Portage::Utils::Depend::parse(" =sys-libs/readline-3 "); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -116,7 +117,7 @@ BOOST_AUTO_TEST_CASE( version1 ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( version2 ) +BOOST_AUTO_TEST_CASE(version2) { auto ds = Portage::Utils::Depend::parse(" =sys-libs/readline2-3 "); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -131,7 +132,7 @@ BOOST_AUTO_TEST_CASE( version2 ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( special ) +BOOST_AUTO_TEST_CASE(special) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0 "); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -144,42 +145,42 @@ BOOST_AUTO_TEST_CASE( special ) BOOST_REQUIRE(ds[0]->when.empty()); } -BOOST_AUTO_TEST_CASE( versionSuffix ) +BOOST_AUTO_TEST_CASE(versionSuffix) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0_alpha "); BOOST_REQUIRE(ds[0]->version); BOOST_REQUIRE_EQUAL(*ds[0]->version, "2.0.0_alpha"); } -BOOST_AUTO_TEST_CASE( versionSuffixNum ) +BOOST_AUTO_TEST_CASE(versionSuffixNum) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0_alpha43 "); BOOST_REQUIRE(ds[0]->version); BOOST_REQUIRE_EQUAL(*ds[0]->version, "2.0.0_alpha43"); } -BOOST_AUTO_TEST_CASE( versionSuffixNumRev ) +BOOST_AUTO_TEST_CASE(versionSuffixNumRev) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0_alpha43-r33 "); BOOST_REQUIRE(ds[0]->version); BOOST_REQUIRE_EQUAL(*ds[0]->version, "2.0.0_alpha43-r33"); } -BOOST_AUTO_TEST_CASE( versionLetter ) +BOOST_AUTO_TEST_CASE(versionLetter) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0g "); BOOST_REQUIRE(ds[0]->version); BOOST_REQUIRE_EQUAL(*ds[0]->version, "2.0.0g"); } -BOOST_AUTO_TEST_CASE( versionRange ) +BOOST_AUTO_TEST_CASE(versionRange) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0* "); BOOST_REQUIRE(ds[0]->version); BOOST_REQUIRE_EQUAL(*ds[0]->version, "2.0.0*"); } -BOOST_AUTO_TEST_CASE( versionSlot ) +BOOST_AUTO_TEST_CASE(versionSlot) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0:foo"); BOOST_REQUIRE(ds[0]->version); @@ -189,7 +190,7 @@ BOOST_AUTO_TEST_CASE( versionSlot ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( slot ) +BOOST_AUTO_TEST_CASE(slot) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+:foo"); BOOST_REQUIRE(!ds[0]->version); @@ -198,7 +199,7 @@ BOOST_AUTO_TEST_CASE( slot ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( versionSlotSubSlot ) +BOOST_AUTO_TEST_CASE(versionSlotSubSlot) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+-2.0.0:foo/bar"); BOOST_REQUIRE(ds[0]->version); @@ -208,7 +209,7 @@ BOOST_AUTO_TEST_CASE( versionSlotSubSlot ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( slotUse ) +BOOST_AUTO_TEST_CASE(slotUse) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+:foo[bar,baz]"); BOOST_REQUIRE(!ds[0]->version); @@ -219,7 +220,7 @@ BOOST_AUTO_TEST_CASE( slotUse ) BOOST_REQUIRE_EQUAL(ds[0]->use[1], "baz"); } -BOOST_AUTO_TEST_CASE( use ) +BOOST_AUTO_TEST_CASE(use) { auto ds = Portage::Utils::Depend::parse(" >x11-libs/Gtk+[moo,cow]"); BOOST_REQUIRE(!ds[0]->version); @@ -229,7 +230,7 @@ BOOST_AUTO_TEST_CASE( use ) BOOST_REQUIRE_EQUAL(ds[0]->use[1], "moo"); } -BOOST_AUTO_TEST_CASE( aorb ) +BOOST_AUTO_TEST_CASE(aorb) { auto ds = Portage::Utils::Depend::parse(" || ( cat/a cat/b ) "); BOOST_REQUIRE_EQUAL(ds.size(), 2); @@ -237,7 +238,7 @@ BOOST_AUTO_TEST_CASE( aorb ) BOOST_REQUIRE(ds[1]->when.empty()); } -BOOST_AUTO_TEST_CASE( deepor ) +BOOST_AUTO_TEST_CASE(deepor) { auto ds = Portage::Utils::Depend::parse(" || ( ( cat/c cat/d ) ( cat/a cat/b ) ) "); BOOST_REQUIRE_EQUAL(ds.size(), 4); @@ -247,7 +248,7 @@ BOOST_AUTO_TEST_CASE( deepor ) BOOST_REQUIRE(ds[3]->when.empty()); } -BOOST_AUTO_TEST_CASE( annoyed1 ) +BOOST_AUTO_TEST_CASE(annoyed1) { auto ds = Portage::Utils::Depend::parse(" !<=app-emulation/emul-linux-x86-baselibs-20140508-r1 "); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -262,13 +263,21 @@ BOOST_AUTO_TEST_CASE( annoyed1 ) BOOST_REQUIRE(ds[0]->use.empty()); } -BOOST_AUTO_TEST_CASE( freeciv ) +BOOST_AUTO_TEST_CASE(freeciv) { - auto ds = Portage::Utils::Depend::parse("app-arch/bzip2 app-arch/xz-utils net-misc/curl sys-libs/zlib auth? ( mysql? ( virtual/mysql ) sqlite? ( dev-db/sqlite:3 ) !mysql? ( ( !sqlite? ( virtual/mysql ) ) ) ) readline? ( sys-libs/readline:0 ) dedicated? ( aimodules? ( dev-libs/libltdl:0 ) ) !dedicated? ( media-libs/libpng:0 gtk? ( x11-libs/gtk+:2 ) mapimg? ( media-gfx/imagemagick ) modpack? ( x11-libs/gtk+:2 ) nls? ( virtual/libintl ) qt5? ( dev-qt/qtcore:5 dev-qt/qtgui:5 dev-qt/qtwidgets:5 ) sdl? ( media-libs/libsdl[video] media-libs/sdl-gfx media-libs/sdl-image[png] media-libs/sdl-ttf ) server? ( aimodules? ( sys-devel/libtool:2 ) ) sound? ( media-libs/libsdl[sound] media-libs/sdl-mixer[vorbis] ) !sdl? ( !gtk? ( x11-libs/gtk+:2 ) ) ) system-lua? ( >=dev-lang/lua-5.2 ) games-misc/games-envd"); + auto ds = Portage::Utils::Depend::parse( + "app-arch/bzip2 app-arch/xz-utils net-misc/curl sys-libs/zlib auth? ( mysql? ( virtual/mysql ) sqlite? ( " + "dev-db/sqlite:3 ) !mysql? ( ( !sqlite? ( virtual/mysql ) ) ) ) readline? ( sys-libs/readline:0 ) " + "dedicated? ( aimodules? ( dev-libs/libltdl:0 ) ) !dedicated? ( media-libs/libpng:0 gtk? ( x11-libs/gtk+:2 " + ") mapimg? ( media-gfx/imagemagick ) modpack? ( x11-libs/gtk+:2 ) nls? ( virtual/libintl ) qt5? ( " + "dev-qt/qtcore:5 dev-qt/qtgui:5 dev-qt/qtwidgets:5 ) sdl? ( media-libs/libsdl[video] media-libs/sdl-gfx " + "media-libs/sdl-image[png] media-libs/sdl-ttf ) server? ( aimodules? ( sys-devel/libtool:2 ) ) sound? ( " + "media-libs/libsdl[sound] media-libs/sdl-mixer[vorbis] ) !sdl? ( !gtk? ( x11-libs/gtk+:2 ) ) ) system-lua? " + "( >=dev-lang/lua-5.2 ) games-misc/games-envd"); BOOST_REQUIRE_EQUAL(ds.size(), 27); } -BOOST_AUTO_TEST_CASE( useWithAtSymble ) +BOOST_AUTO_TEST_CASE(useWithAtSymble) { auto ds = Portage::Utils::Depend::parse("some@thing? ( app-arch/bzip2 )"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -276,7 +285,7 @@ BOOST_AUTO_TEST_CASE( useWithAtSymble ) BOOST_REQUIRE_EQUAL(ds[0]->when.front(), "some@thing"); } -BOOST_AUTO_TEST_CASE( underscoreInPackage ) +BOOST_AUTO_TEST_CASE(underscoreInPackage) { auto ds = Portage::Utils::Depend::parse(">=dev-ros/costmap_2d-1.13.1"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -286,7 +295,7 @@ BOOST_AUTO_TEST_CASE( underscoreInPackage ) BOOST_REQUIRE_EQUAL(*ds[0]->version, "1.13.1"); } -BOOST_AUTO_TEST_CASE( multipleSuffix ) +BOOST_AUTO_TEST_CASE(multipleSuffix) { auto ds = Portage::Utils::Depend::parse(">=sys-fs/btrfs-progs-0.20_rc1_p358"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -296,7 +305,7 @@ BOOST_AUTO_TEST_CASE( multipleSuffix ) BOOST_REQUIRE_EQUAL(*ds[0]->version, "0.20_rc1_p358"); } -BOOST_AUTO_TEST_CASE( thisThing ) +BOOST_AUTO_TEST_CASE(thisThing) { auto ds = Portage::Utils::Depend::parse("!<=dev-libs/9libs-1.0"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -308,7 +317,7 @@ BOOST_AUTO_TEST_CASE( thisThing ) BOOST_REQUIRE_EQUAL(*ds[0]->version, "1.0"); } -BOOST_AUTO_TEST_CASE( thatThing ) +BOOST_AUTO_TEST_CASE(thatThing) { auto ds = Portage::Utils::Depend::parse("!sys-firmware/iwl3160-7260-bt-ucode"); BOOST_REQUIRE_EQUAL(ds.size(), 1); @@ -318,4 +327,3 @@ BOOST_AUTO_TEST_CASE( thatThing ) BOOST_REQUIRE_EQUAL(ds[0]->package, "iwl3160-7260-bt-ucode"); BOOST_REQUIRE(!ds[0]->version); } - diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index da0e6cd..19ed59a 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -2,16 +2,17 @@ #include <boost/test/unit_test.hpp> #include "mockDefs.h" -#include <definedDirs.h> #include <buffer.h> -#include <modifycommand.h> -#include <git2.h> +#include <definedDirs.h> #include <fstream> +#include <git2.h> #include <maintenanceimpl.h> -#include <portageimpl.h> #include <mockPool.h> +#include <modifycommand.h> +#include <portageimpl.h> -class MaintenanceClientCombined : public Maintenance, public TestClient { }; +class MaintenanceClientCombined : public Maintenance, public TestClient { +}; BOOST_FIXTURE_TEST_SUITE(maintenance, MaintenanceClientCombined) @@ -68,86 +69,90 @@ dumpDb(DB::ConnectionPtr db) } class M2 : public Gentoo::Service::Maintenance { - public: - typedef std::map<std::filesystem::path, size_t> FileMap; - - M2(const DB::ConnectionPoolPtr & d) : - Gentoo::Service::Maintenance(d) - { - } - - void applyDiffOfFolders(const std::filesystem::path & from, const std::filesystem::path & to) const - { - auto dbc = db->get(); - auto fromFiles = fileSet(from); - auto toFiles = fileSet(to); - DB::TransactionScope tx(*dbc.get()); - Gentoo::Service::ChangeSet changes; - newFiles(changes, fromFiles, toFiles); - removedFiles(changes, fromFiles, toFiles); - changedFiles(changes, fromFiles, toFiles); - std::filesystem::remove(treeDir); - std::filesystem::create_symlink(to, treeDir); - Gentoo::Repository repo = { 1, "gentoo", to.string(), "origin", "master", "" }; - applyFileChanges(dbc.get(), "/", repo, changes); - std::filesystem::remove(treeDir); - } +public: + typedef std::map<std::filesystem::path, size_t> FileMap; + + M2(const DB::ConnectionPoolPtr & d) : Gentoo::Service::Maintenance(d) { } + + void + applyDiffOfFolders(const std::filesystem::path & from, const std::filesystem::path & to) const + { + auto dbc = db->get(); + auto fromFiles = fileSet(from); + auto toFiles = fileSet(to); + DB::TransactionScope tx(*dbc.get()); + Gentoo::Service::ChangeSet changes; + newFiles(changes, fromFiles, toFiles); + removedFiles(changes, fromFiles, toFiles); + changedFiles(changes, fromFiles, toFiles); + std::filesystem::remove(treeDir); + std::filesystem::create_symlink(to, treeDir); + Gentoo::Repository repo = {1, "gentoo", to.string(), "origin", "master", ""}; + applyFileChanges(dbc.get(), "/", repo, changes); + std::filesystem::remove(treeDir); + } - static FileMap fileSet(const std::filesystem::path & p) - { - FileMap found; - for (std::filesystem::recursive_directory_iterator r(p); r != std::filesystem::recursive_directory_iterator(); r++) { - if (std::filesystem::is_regular_file(r->status())) { - found[std::filesystem::relative(*r, p)] = std::filesystem::file_size(*r); - } + static FileMap + fileSet(const std::filesystem::path & p) + { + FileMap found; + for (std::filesystem::recursive_directory_iterator r(p); r != std::filesystem::recursive_directory_iterator(); + r++) { + if (std::filesystem::is_regular_file(r->status())) { + found[std::filesystem::relative(*r, p)] = std::filesystem::file_size(*r); } - return found; } + return found; + } - static Gentoo::Service::PathParts split(const std::filesystem::path & path) - { - Gentoo::Service::PathParts pp; - for (const auto & p : path) { - pp.push_back(p.string()); - } - return pp; + static Gentoo::Service::PathParts + split(const std::filesystem::path & path) + { + Gentoo::Service::PathParts pp; + for (const auto & p : path) { + pp.push_back(p.string()); } + return pp; + } - static void newFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) - { - for(const auto & f : to) { - if (from.find(f.first) == from.end()) { - changes[f.first] = { split(f.first), GIT_DELTA_ADDED }; - } + static void + newFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) + { + for (const auto & f : to) { + if (from.find(f.first) == from.end()) { + changes[f.first] = {split(f.first), GIT_DELTA_ADDED}; } } - static void removedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) - { - for(const auto & f : from) { - if (to.find(f.first) == to.end()) { - changes[f.first] = { split(f.first), GIT_DELTA_DELETED }; - } + } + static void + removedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) + { + for (const auto & f : from) { + if (to.find(f.first) == to.end()) { + changes[f.first] = {split(f.first), GIT_DELTA_DELETED}; } } - static void changedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) - { - for(const auto & f : to) { - auto i = from.find(f.first); - if (i != from.end() && i->second != f.second) { - changes[f.first] = { split(f.first), GIT_DELTA_MODIFIED }; - } + } + static void + changedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) + { + for (const auto & f : to) { + auto i = from.find(f.first); + if (i != from.end() && i->second != f.second) { + changes[f.first] = {split(f.first), GIT_DELTA_MODIFIED}; } } + } }; #define BOOST_TEST_CONTEXT_VAR(VAR, EXPR) \ - BOOST_TEST_CONTEXT(#EXPR) \ - for (auto VAR = EXPR, * __context__run = &VAR; __context__run; __context__run = NULL) + BOOST_TEST_CONTEXT(#EXPR) for (auto VAR = EXPR, *__context__run = &VAR; __context__run; __context__run = NULL) -BOOST_AUTO_TEST_CASE( refreshPackageTree ) +BOOST_AUTO_TEST_CASE(refreshPackageTree) { auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI")); - auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); + auto insRepo = db->modify( + "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); insRepo->bindParamS(0, "gentoo"); insRepo->bindParamS(1, treeDir.string()); insRepo->bindParamS(2, "origin"); @@ -162,12 +167,13 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) BOOST_TEST_CONTEXT("4156eb45cf3b0ce1d7125b84efd8688c2d6e831d") { m2.applyDiffOfFolders(binDir / "empty", rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d"); - doRefreshPackageTree(db, - 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543, 81, 152, 7); + doRefreshPackageTree(db, 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543, 81, 152, 7); Gentoo::PortagePtr portage = std::make_shared<Gentoo::Service::Portage>(p); - BOOST_TEST_CONTEXT_VAR(acjtr, portage->findPackage("app-crypt", "johntheripper", Ice::Current())) { - BOOST_TEST_CONTEXT_VAR(acjtrUses, portage->getPackageUses(acjtr->packageid, Ice::Current())) { + BOOST_TEST_CONTEXT_VAR(acjtr, portage->findPackage("app-crypt", "johntheripper", Ice::Current())) + { + BOOST_TEST_CONTEXT_VAR(acjtrUses, portage->getPackageUses(acjtr->packageid, Ice::Current())) + { BOOST_REQUIRE_EQUAL(9, acjtrUses.size()); BOOST_REQUIRE_EQUAL("custom-cflags", acjtrUses[1]->use); BOOST_REQUIRE(!acjtrUses[1]->defaultflag); @@ -182,8 +188,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) BOOST_REQUIRE_EQUAL("cpu_flags_x86", *acjtrUses[7]->group); } } - BOOST_TEST_CONTEXT_VAR(nms, portage->findPackage("net-proxy", "squid", Ice::Current())) { - BOOST_TEST_CONTEXT_VAR(nmsUses, portage->getPackageUses(nms->packageid, Ice::Current())) { + BOOST_TEST_CONTEXT_VAR(nms, portage->findPackage("net-proxy", "squid", Ice::Current())) + { + BOOST_TEST_CONTEXT_VAR(nmsUses, portage->getPackageUses(nms->packageid, Ice::Current())) + { BOOST_REQUIRE_EQUAL(30, nmsUses.size()); BOOST_REQUIRE_EQUAL("caps", nmsUses[0]->use); BOOST_REQUIRE(!nmsUses[0]->defaultflag); @@ -197,21 +205,19 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) } BOOST_TEST_CONTEXT("756569aa764177340726dd3d40b41d89b11b20c7") { - m2.applyDiffOfFolders(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7"); - doRefreshPackageTree(db, - 5, 1, 483, 982, 3638, 4599, 502, 393, 238, 50, 1573, 2009, 1546, 79, 152, 10); + m2.applyDiffOfFolders(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", + rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7"); + doRefreshPackageTree(db, 5, 1, 483, 982, 3638, 4599, 502, 393, 238, 50, 1573, 2009, 1546, 79, 152, 10); } BOOST_TEST_CONTEXT("empty") { m2.applyDiffOfFolders(rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7", binDir / "empty"); - doRefreshPackageTree(db, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + doRefreshPackageTree(db, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } } -static -git_oid -create_initial_commit(git_repository *repo) +static git_oid +create_initial_commit(git_repository * repo) { git_signature * sig; git_index * index; @@ -222,7 +228,7 @@ create_initial_commit(git_repository *repo) BOOST_REQUIRE_EQUAL(0, git_repository_index(&index, repo)); BOOST_REQUIRE_EQUAL(0, git_index_write_tree(&tree_id, index)); BOOST_REQUIRE_EQUAL(0, git_tree_lookup(&tree, repo, &tree_id)); - BOOST_REQUIRE_EQUAL(0, git_commit_create_v( &commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0)); + BOOST_REQUIRE_EQUAL(0, git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0)); git_index_free(index); git_tree_free(tree); @@ -230,7 +236,7 @@ create_initial_commit(git_repository *repo) return commit_id; } -BOOST_AUTO_TEST_CASE( testUpdateGitRepository ) +BOOST_AUTO_TEST_CASE(testUpdateGitRepository) { auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI")); auto testRepo = binDir / "testrepo"; @@ -249,7 +255,8 @@ BOOST_AUTO_TEST_CASE( testUpdateGitRepository ) git_repository_free(repo); git_libgit2_shutdown(); // Reference it - auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); + auto insRepo = db->modify( + "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); insRepo->bindParamS(0, "testrepo"); insRepo->bindParamS(1, testRepo.string()); insRepo->bindParamS(2, "origin"); @@ -268,10 +275,11 @@ BOOST_AUTO_TEST_CASE( testUpdateGitRepository ) BOOST_REQUIRE(std::filesystem::is_regular_file(testRepo / "net-misc" / "gentoobrowse-api" / "Manifest")); } -BOOST_AUTO_TEST_CASE( testRefreshGitRepository ) +BOOST_AUTO_TEST_CASE(testRefreshGitRepository) { auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI")); - auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); + auto insRepo = db->modify( + "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)"); insRepo->bindParamS(0, "gentoo"); insRepo->bindParamS(1, "/usr/portage"); insRepo->bindParamS(2, "origin"); @@ -282,42 +290,59 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository ) db->executeScript(data, rootDir); BOOST_TEST_CONTEXT("Intiial values") { - SQL_REQUIRE_EQUAL(R"SQL(SELECT name FROM gentoobrowse.packages p WHERE p.packageid = 9)SQL", std::string, "libkgapi"); + SQL_REQUIRE_EQUAL( + R"SQL(SELECT name FROM gentoobrowse.packages p WHERE p.packageid = 9)SQL", std::string, "libkgapi"); SQL_REQUIRE_EQUAL(R"SQL(SELECT p.categoryid FROM gentoobrowse.categories c, gentoobrowse.packages p - WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", int64_t, 6); + WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", + int64_t, 6); SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 9)SQL", int64_t, 2); - SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2); - SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 9); + SQL_REQUIRE_EQUAL( + R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2); + SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", + int64_t, 9); } // Import it m->refreshPackageTree(); - SQL_REQUIRE_EQUAL(R"SQL(SELECT lastCommit FROM gentoobrowse.repos)SQL", std::string, "40539afe6705aee26a55bb861f5e892ae7240057"); + SQL_REQUIRE_EQUAL(R"SQL(SELECT lastCommit FROM gentoobrowse.repos)SQL", std::string, + "40539afe6705aee26a55bb861f5e892ae7240057"); BOOST_TEST_CONTEXT("libkgapi was moved correctly") { BOOST_TEST_CONTEXT("from net-libs to kde-apps") { SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.categories c, gentoobrowse.packages p - WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 1); + WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", + int64_t, 1); SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.categories c, gentoobrowse.packages p - WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", int64_t, 0); + WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", + int64_t, 0); } BOOST_TEST_CONTEXT("And it was created new in the right category") { SQL_REQUIRE_EQUAL(R"SQL(SELECT p.packageid FROM gentoobrowse.categories c, gentoobrowse.packages p - WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 28); + WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", + int64_t, 28); SQL_REQUIRE_EQUAL(R"SQL(SELECT p.categoryid FROM gentoobrowse.categories c, gentoobrowse.packages p - WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 8); + WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", + int64_t, 8); } BOOST_TEST_CONTEXT("Original ebuilds in moved package were deleted") { SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 9)SQL", int64_t, 0); - SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 28)SQL", int64_t, 2); - SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 0); + SQL_REQUIRE_EQUAL( + R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 28)SQL", int64_t, 2); + SQL_REQUIRE_EQUAL( + R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 0); } } BOOST_TEST_CONTEXT("Change log was imported correctly") { SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog", int64_t, 43); - SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = 'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", int64_t, 1); - SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = '8292397bf6a8c91215b03a558e8bc843aff25b64'", int64_t, 0); - SQL_REQUIRE_EQUAL("SELECT ARRAY_LENGTH(files, 1) FROM gentoobrowse.changelog WHERE commitid = 'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", int64_t, 5); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = " + "'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", + int64_t, 1); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = " + "'8292397bf6a8c91215b03a558e8bc843aff25b64'", + int64_t, 0); + SQL_REQUIRE_EQUAL("SELECT ARRAY_LENGTH(files, 1) FROM gentoobrowse.changelog WHERE commitid = " + "'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", + int64_t, 5); #if DUMPDB db->execute("COPY gentoobrowse.changelog TO '/tmp/changelog.tsv'"); #endif @@ -325,4 +350,3 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/gentoobrowse-api/unittests/testMaintenanceBits.cpp b/gentoobrowse-api/unittests/testMaintenanceBits.cpp index c7104d9..9c16f74 100644 --- a/gentoobrowse-api/unittests/testMaintenanceBits.cpp +++ b/gentoobrowse-api/unittests/testMaintenanceBits.cpp @@ -3,16 +3,16 @@ #include <maintenance/abstractFileProcessor.h> -BOOST_AUTO_TEST_CASE( match ) +BOOST_AUTO_TEST_CASE(match) { - std::filesystem::path path { "metadata/md5-cache/app-admin/conky-1.10.6-r1" }; - Gentoo::Service::PathParts pp { path.begin(), path.end() }; + std::filesystem::path path {"metadata/md5-cache/app-admin/conky-1.10.6-r1"}; + Gentoo::Service::PathParts pp {path.begin(), path.end()}; BOOST_REQUIRE_EQUAL(4, pp.size()); BOOST_CHECK_EQUAL("metadata", pp[0]); BOOST_CHECK_EQUAL("md5-cache", pp[1]); } -BOOST_AUTO_TEST_CASE( compose ) +BOOST_AUTO_TEST_CASE(compose) { // std::filesystem composes slightly differently to boost::filesystem // Specifically "/base" / "/sub" @@ -24,4 +24,3 @@ BOOST_AUTO_TEST_CASE( compose ) std::filesystem::path comp = base / std::filesystem::path(sub).lexically_relative("/") / file; BOOST_CHECK_EQUAL("/base/sub/file", comp); } - diff --git a/gentoobrowse-api/unittests/testMasks.cpp b/gentoobrowse-api/unittests/testMasks.cpp index 3fc40e9..7f37d3b 100644 --- a/gentoobrowse-api/unittests/testMasks.cpp +++ b/gentoobrowse-api/unittests/testMasks.cpp @@ -1,38 +1,40 @@ #define BOOST_TEST_MODULE Masks #include <boost/test/unit_test.hpp> -#include <mask.h> -#include <fileUtils.h> +#include <boost/algorithm/string/join.hpp> +#include <compileTimeFormatter.h> #include <definedDirs.h> +#include <fileUtils.h> +#include <mask.h> #include <portage-models.h> -#include <compileTimeFormatter.h> -#include <boost/algorithm/string/join.hpp> class MaskTester : public Portage::Utils::Masks { - protected: - void consume() const override - { - if (email && person) { - masks.push_back(std::make_shared<Gentoo::Mask>(n, person->raw(), email->raw(), date, - boost::algorithm::join(message, " "), - Gentoo::StringList(atoms.begin(), atoms.end()))); - } +protected: + void + consume() const override + { + if (email && person) { + masks.push_back(std::make_shared<Gentoo::Mask>(n, person->raw(), email->raw(), date, + boost::algorithm::join(message, " "), Gentoo::StringList(atoms.begin(), atoms.end()))); } + } - public: - mutable Gentoo::Masks masks; +public: + mutable Gentoo::Masks masks; }; -#define BOOST_CHECK_EQUAL_COLLECTION(a, ...) { \ - auto __list__ = { __VA_ARGS__ }; \ - BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), __list__.begin(), __list__.end()); \ -} +#define BOOST_CHECK_EQUAL_COLLECTION(a, ...) \ + { \ + auto __list__ = {__VA_ARGS__}; \ + BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), __list__.begin(), __list__.end()); \ + } BOOST_FIXTURE_TEST_SUITE(mt, MaskTester) BOOST_AUTO_TEST_CASE(f1) { - AdHoc::FileUtils::MemMap f(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "profiles" / "package.mask"); + AdHoc::FileUtils::MemMap f( + rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "profiles" / "package.mask"); extract((const gchar *)f.data, f.getStat().st_size); BOOST_CHECK_EQUAL(masks.size(), 151); auto m = masks.front(); @@ -42,10 +44,8 @@ BOOST_AUTO_TEST_CASE(f1) BOOST_CHECK_EQUAL("chewi@gentoo.org", *m->email); BOOST_CHECK_EQUAL("1016-04-25", m->dateadded); BOOST_CHECK_EQUAL("Long dead upstream and no longer needed. Removal in 30 days.", m->message); - BOOST_CHECK_EQUAL_COLLECTION(m->atomspec, - "dev-java/charva", - "dev-java/jakarta-slide-webdavclient", - "dev-java/xml-im-exporter"); + BOOST_CHECK_EQUAL_COLLECTION( + m->atomspec, "dev-java/charva", "dev-java/jakarta-slide-webdavclient", "dev-java/xml-im-exporter"); } BOOST_AUTO_TEST_CASE(whitespaceline) @@ -75,4 +75,3 @@ dev-python/py2-ipaddress } BOOST_AUTO_TEST_SUITE_END() - diff --git a/gentoobrowse-api/unittests/testNews.cpp b/gentoobrowse-api/unittests/testNews.cpp index b2c8a78..b8944ae 100644 --- a/gentoobrowse-api/unittests/testNews.cpp +++ b/gentoobrowse-api/unittests/testNews.cpp @@ -1,13 +1,14 @@ #define BOOST_TEST_MODULE TestNews #include <boost/test/unit_test.hpp> -#include <news.h> -#include <fileUtils.h> #include <definedDirs.h> +#include <fileUtils.h> +#include <news.h> -BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable ) +BOOST_AUTO_TEST_CASE(news_2016_04_07_kde_plasma5_stable) { - AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2016-04-07-kde-plasma5-stable" / "2016-04-07-kde-plasma5-stable.en.txt"); + AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" + / "2016-04-07-kde-plasma5-stable" / "2016-04-07-kde-plasma5-stable.en.txt"); auto news = Portage::Utils::News::parse(m.sv()); BOOST_REQUIRE_EQUAL(news->title, "KDE Plasma 5 Upgrade"); BOOST_REQUIRE(news->authorname); @@ -15,20 +16,23 @@ BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable ) BOOST_REQUIRE(news->authoremail); BOOST_REQUIRE_EQUAL(*news->authoremail, "kensington@gentoo.org"); BOOST_REQUIRE_EQUAL(news->posted, "2016-04-02"); - for(const auto & s : news->body) { + for (const auto & s : news->body) { BOOST_TEST_INFO(s); } BOOST_REQUIRE_EQUAL(news->body.size(), 6); - BOOST_REQUIRE_EQUAL(news->body[0], "KDE Workspaces 4.11 has reached end of life and is no longer supported by upstream. It is therefore recommended for all users to upgrade to KDE Plasma 5."); + BOOST_REQUIRE_EQUAL(news->body[0], + "KDE Workspaces 4.11 has reached end of life and is no longer supported by upstream. It is therefore " + "recommended for all users to upgrade to KDE Plasma 5."); BOOST_REQUIRE_EQUAL(news->urls.size(), 2); BOOST_REQUIRE_EQUAL(news->urls[0], "https://wiki.gentoo.org/wiki/KDE/Plasma_5_upgrade"); BOOST_REQUIRE_EQUAL(news->atomspec.size(), 1); BOOST_REQUIRE_EQUAL(news->atomspec[0], "kde-base/plasma-workspace"); } -BOOST_AUTO_TEST_CASE( news_2010_03_23_new_subprofiles ) +BOOST_AUTO_TEST_CASE(news_2010_03_23_new_subprofiles) { - AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2010-03-23-new-subprofiles" / "2010-03-23-new-subprofiles.en.txt"); + AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" + / "2010-03-23-new-subprofiles" / "2010-03-23-new-subprofiles.en.txt"); auto news = Portage::Utils::News::parse(m.sv()); BOOST_REQUIRE_EQUAL(news->title, "New desktop subprofiles for GNOME and KDE"); BOOST_REQUIRE(news->authorname); @@ -36,7 +40,7 @@ BOOST_AUTO_TEST_CASE( news_2010_03_23_new_subprofiles ) BOOST_REQUIRE(news->authoremail); BOOST_REQUIRE_EQUAL(*news->authoremail, "tampakrap@gentoo.org"); BOOST_REQUIRE_EQUAL(news->posted, "2010-03-23"); - for(const auto & s : news->body) { + for (const auto & s : news->body) { BOOST_TEST_INFO(s); } BOOST_REQUIRE_EQUAL(news->body.size(), 3); @@ -44,4 +48,3 @@ BOOST_AUTO_TEST_CASE( news_2010_03_23_new_subprofiles ) BOOST_REQUIRE_EQUAL(news->urls.size(), 0); BOOST_REQUIRE_EQUAL(news->atomspec.size(), 0); } - diff --git a/gentoobrowse-api/unittests/testNotifications.cpp b/gentoobrowse-api/unittests/testNotifications.cpp index fb105b8..ddd1fa7 100644 --- a/gentoobrowse-api/unittests/testNotifications.cpp +++ b/gentoobrowse-api/unittests/testNotifications.cpp @@ -1,19 +1,19 @@ #define BOOST_TEST_MODULE TestNotifications -#include <boost/test/unit_test.hpp> #include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> #include "mockDefs.h" #include <definedDirs.h> #include <fstream> +#include <memstream.h> +#include <mimeImpl.h> #include <regex> #include <tidy.h> -#include <mimeImpl.h> -#include <memstream.h> using namespace std::string_literals; using QPTD = std::tuple<std::string_view, std::string_view>; -BOOST_GLOBAL_FIXTURE( Mail ); +BOOST_GLOBAL_FIXTURE(Mail); BOOST_FIXTURE_TEST_SUITE(tp, TestClient); @@ -44,17 +44,19 @@ commonAssert(IceTray::Mail::EmailPtr e) BOOST_REQUIRE_NE(html->payload.find("https://cdnjs.cloudflare.com/"), std::string::npos); } -BOOST_AUTO_TEST_CASE( testSend, * boost::unit_test::disabled() ) +BOOST_AUTO_TEST_CASE(testSend, *boost::unit_test::disabled()) { - Gentoo::NewUserPtr u = std::make_shared<Gentoo::NewUser>(1, "testuser", "Test User", "dan@randomdan.homeip.net", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); + Gentoo::NewUserPtr u = std::make_shared<Gentoo::NewUser>( + 1, "testuser", "Test User", "dan@randomdan.homeip.net", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); auto e = n->getSignup(u); BOOST_REQUIRE(e); ms->sendEmail(e); } -BOOST_AUTO_TEST_CASE( testSignup ) +BOOST_AUTO_TEST_CASE(testSignup) { - Gentoo::NewUserPtr u = std::make_shared<Gentoo::NewUser>(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); + Gentoo::NewUserPtr u = std::make_shared<Gentoo::NewUser>( + 1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); auto e = n->getSignup(u); BOOST_REQUIRE(e); BOOST_REQUIRE_EQUAL(e->subject, "Gentoo Browse: Welcome"); @@ -64,53 +66,53 @@ BOOST_AUTO_TEST_CASE( testSignup ) BOOST_REQUIRE_EQUAL(e->to.address, "test@user.com"); commonAssert(e); lintable_test_files("signup", e); - auto [ plainPart, htmlPart ] = humanReadableParts(e); - for (auto text : { plainPart, htmlPart }) { + auto [plainPart, htmlPart] = humanReadableParts(e); + for (auto text : {plainPart, htmlPart}) { BOOST_REQUIRE(text); BOOST_REQUIRE(text->payload.find("Welcome to Gentoo Browse") != std::string::npos); - BOOST_REQUIRE(text->payload.find("https://gentoobrowse.randomdan.homeip.net/user/verification/some-guid/testuser") != std::string::npos); - BOOST_REQUIRE(std::regex_search(text->payload, - std::regex("confirmation\\s+page:\\s+some-guid"))); + BOOST_REQUIRE( + text->payload.find("https://gentoobrowse.randomdan.homeip.net/user/verification/some-guid/testuser") + != std::string::npos); + BOOST_REQUIRE(std::regex_search(text->payload, std::regex("confirmation\\s+page:\\s+some-guid"))); } } -BOOST_AUTO_TEST_CASE( testNews ) +BOOST_AUTO_TEST_CASE(testNews) { - Gentoo::UserPtr u = std::make_shared<Gentoo::User>(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None); - Gentoo::NewsContent nc { - { - std::make_shared<Gentoo::Category>(1, "app-test", "Test cat1"s), - std::make_shared<Gentoo::Category>(2, "sys-test", "Test cat2"s), - std::make_shared<Gentoo::Category>(3, "no-show", "Unused cat"s) - }, - { - std::make_shared<Gentoo::Package>(1, 1, "app1", "first-seen", "Test app desc one", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared<Gentoo::Package>(2, 1, "app2", "first-seen", "Test app desc two", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared<Gentoo::Package>(3, 2, "app3", "first-seen", "Test app desc three", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared<Gentoo::Package>(4, 2, "app4", "first-seen", "Test app no-show", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None) - }, - { - std::make_shared<Gentoo::Ebuild>(1, 1, 1, "1.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(2, 1, 1, "1.1a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(3, 1, 1, "1.2a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(4, 2, 1, "2.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(5, 3, 1, "3.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(6, 2, 1, "2.1a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared<Gentoo::Ebuild>(7, 3, 1, "3.1a", "slot", "first-seen", "last-mod", IceUtil::None) - } - }; + Gentoo::UserPtr u = std::make_shared<Gentoo::User>( + 1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None); + Gentoo::NewsContent nc {{std::make_shared<Gentoo::Category>(1, "app-test", "Test cat1"s), + std::make_shared<Gentoo::Category>(2, "sys-test", "Test cat2"s), + std::make_shared<Gentoo::Category>(3, "no-show", "Unused cat"s)}, + {std::make_shared<Gentoo::Package>(1, 1, "app1", "first-seen", "Test app desc one", "Test summary 1"s, + IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared<Gentoo::Package>(2, 1, "app2", "first-seen", "Test app desc two", + "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared<Gentoo::Package>(3, 2, "app3", "first-seen", "Test app desc three", + "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared<Gentoo::Package>(4, 2, "app4", "first-seen", "Test app no-show", "Test summary 1"s, + IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None)}, + {std::make_shared<Gentoo::Ebuild>(1, 1, 1, "1.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>(2, 1, 1, "1.1a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>(3, 1, 1, "1.2a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>(4, 2, 1, "2.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>(5, 3, 1, "3.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>(6, 2, 1, "2.1a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared<Gentoo::Ebuild>( + 7, 3, 1, "3.1a", "slot", "first-seen", "last-mod", IceUtil::None)}}; auto e = n->getNews(u, nc); commonAssert(e); lintable_test_files("news", e); - auto [ plainPart, htmlPart ] = humanReadableParts(e); - for (auto text : { plainPart, htmlPart }) { + auto [plainPart, htmlPart] = humanReadableParts(e); + for (auto text : {plainPart, htmlPart}) { BOOST_REQUIRE(text); BOOST_REQUIRE(text->payload.find("Latest news") != std::string::npos); - BOOST_REQUIRE(text->payload.find("https://gentoobrowse.randomdan.homeip.net/packages/app-test") != std::string::npos); - BOOST_REQUIRE(text->payload.find("https://gentoobrowse.randomdan.homeip.net/packages/app-test/app") != std::string::npos); + BOOST_REQUIRE( + text->payload.find("https://gentoobrowse.randomdan.homeip.net/packages/app-test") != std::string::npos); + BOOST_REQUIRE(text->payload.find("https://gentoobrowse.randomdan.homeip.net/packages/app-test/app") + != std::string::npos); BOOST_REQUIRE(text->payload.find("no-show") == std::string::npos); } } BOOST_AUTO_TEST_SUITE_END() - diff --git a/gentoobrowse-api/unittests/testNotificationsTriggers.cpp b/gentoobrowse-api/unittests/testNotificationsTriggers.cpp index 562f08a..993b7a0 100644 --- a/gentoobrowse-api/unittests/testNotificationsTriggers.cpp +++ b/gentoobrowse-api/unittests/testNotificationsTriggers.cpp @@ -4,25 +4,31 @@ #include "mockDefs.h" #include <mockMailServer.h> -BOOST_GLOBAL_FIXTURE( Service ); +BOOST_GLOBAL_FIXTURE(Service); BOOST_FIXTURE_TEST_SUITE(tp, TestClient); -BOOST_AUTO_TEST_CASE( triggers ) +BOOST_AUTO_TEST_CASE(triggers) { auto t = m->getUserNews(); BOOST_REQUIRE_EQUAL(1, t.size()); BOOST_REQUIRE_EQUAL(1, t.begin()->first); BOOST_REQUIRE_EQUAL(2, t.begin()->second.categories.size()); - std::sort(t.begin()->second.categories.begin(), t.begin()->second.categories.end(), [](auto a, auto b) { return a->categoryid < b->categoryid; }); + std::sort(t.begin()->second.categories.begin(), t.begin()->second.categories.end(), [](auto a, auto b) { + return a->categoryid < b->categoryid; + }); BOOST_REQUIRE_EQUAL(311, t.begin()->second.categories[0]->categoryid); BOOST_REQUIRE_EQUAL(313, t.begin()->second.categories[1]->categoryid); BOOST_REQUIRE_EQUAL(2, t.begin()->second.packages.size()); - std::sort(t.begin()->second.packages.begin(), t.begin()->second.packages.end(), [](auto a, auto b) { return a->packageid < b->packageid; }); + std::sort(t.begin()->second.packages.begin(), t.begin()->second.packages.end(), [](auto a, auto b) { + return a->packageid < b->packageid; + }); BOOST_REQUIRE_EQUAL(49517, t.begin()->second.packages[0]->packageid); BOOST_REQUIRE_EQUAL(54144, t.begin()->second.packages[1]->packageid); BOOST_REQUIRE_EQUAL(7, t.begin()->second.ebuilds.size()); - std::sort(t.begin()->second.ebuilds.begin(), t.begin()->second.ebuilds.end(), [](auto a, auto b) { return a->ebuildid < b->ebuildid; }); + std::sort(t.begin()->second.ebuilds.begin(), t.begin()->second.ebuilds.end(), [](auto a, auto b) { + return a->ebuildid < b->ebuildid; + }); BOOST_REQUIRE_EQUAL(657508, t.begin()->second.ebuilds[0]->ebuildid); BOOST_REQUIRE_EQUAL(657509, t.begin()->second.ebuilds[1]->ebuildid); BOOST_REQUIRE_EQUAL(658228, t.begin()->second.ebuilds[2]->ebuildid); @@ -32,7 +38,7 @@ BOOST_AUTO_TEST_CASE( triggers ) BOOST_REQUIRE_EQUAL(680613, t.begin()->second.ebuilds[6]->ebuildid); } -BOOST_AUTO_TEST_CASE( send ) +BOOST_AUTO_TEST_CASE(send) { auto ms = std::dynamic_pointer_cast<IceTray::Mail::MockMailServer>(this->ms); BOOST_REQUIRE(ms); @@ -48,4 +54,3 @@ BOOST_AUTO_TEST_CASE( send ) } BOOST_AUTO_TEST_SUITE_END() - diff --git a/gentoobrowse-api/unittests/testPerf.cpp b/gentoobrowse-api/unittests/testPerf.cpp index 863eb03..c0f1a2f 100644 --- a/gentoobrowse-api/unittests/testPerf.cpp +++ b/gentoobrowse-api/unittests/testPerf.cpp @@ -1,20 +1,21 @@ #define BOOST_TEST_MODULE TestPerformance -#include <boost/test/unit_test.hpp> #include <Ice/Ice.h> -#include <portage.h> -#include <vector> -#include <thread> -#include <boost/random/uniform_int_distribution.hpp> -#include <boost/random/mersenne_twister.hpp> #include <boost/date_time/microsec_time_clock.hpp> #include <boost/date_time/posix_time/ptime.hpp> +#include <boost/random/mersenne_twister.hpp> +#include <boost/random/uniform_int_distribution.hpp> +#include <boost/test/unit_test.hpp> +#include <portage.h> +#include <thread> +#include <vector> std::atomic_long count; bool run = true; static const int THREADS = 200; static const int CALLS = 2000; -static void test(Gentoo::PortagePrx p, const Gentoo::Packages & pkgs) +static void +test(Gentoo::PortagePrx p, const Gentoo::Packages & pkgs) { boost::random::mt19937 rng; boost::random::uniform_int_distribution<> pid(0, pkgs.size() - 1); @@ -26,7 +27,7 @@ static void test(Gentoo::PortagePrx p, const Gentoo::Packages & pkgs) count += myCount; } -BOOST_AUTO_TEST_CASE( perf ) +BOOST_AUTO_TEST_CASE(perf) { Ice::StringSeq _args; _args.push_back("--Ice.ThreadPool.Client.Size=50"); @@ -53,4 +54,3 @@ BOOST_AUTO_TEST_CASE( perf ) fprintf(stderr, " - %ld hits/second\n", ((count * 1000) / ((stopTime - startTime).total_milliseconds()))); ic->destroy(); } - diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 18b8114..a530e34 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -3,27 +3,29 @@ #include "mockDefs.h" -BOOST_GLOBAL_FIXTURE( Service ); +BOOST_GLOBAL_FIXTURE(Service); namespace std { template<typename T> ostream & operator<<(ostream & s, const Ice::optional<T> & o) { - if (o) s << *o; - else s << "-empty optional-"; + if (o) + s << *o; + else + s << "-empty optional-"; return s; } } BOOST_FIXTURE_TEST_SUITE(tp, TestClient) -BOOST_AUTO_TEST_CASE( getCategoryMissing ) +BOOST_AUTO_TEST_CASE(getCategoryMissing) { BOOST_REQUIRE_THROW(p->getCategory(0), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getCategory ) +BOOST_AUTO_TEST_CASE(getCategory) { auto cat = p->getCategory(316); BOOST_REQUIRE(cat); @@ -33,12 +35,12 @@ BOOST_AUTO_TEST_CASE( getCategory ) BOOST_REQUIRE_EQUAL(169, cat->summary->length()); } -BOOST_AUTO_TEST_CASE( findCategoryMissing ) +BOOST_AUTO_TEST_CASE(findCategoryMissing) { BOOST_REQUIRE_THROW(p->findCategory("missing"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( findCategory ) +BOOST_AUTO_TEST_CASE(findCategory) { auto cat = p->findCategory("app-backup"); BOOST_REQUIRE(cat); @@ -48,7 +50,7 @@ BOOST_AUTO_TEST_CASE( findCategory ) BOOST_REQUIRE_EQUAL(169, cat->summary->length()); } -BOOST_AUTO_TEST_CASE( getAllCategories ) +BOOST_AUTO_TEST_CASE(getAllCategories) { auto cats = p->getAllCategories(); BOOST_REQUIRE_EQUAL(6, cats.size()); @@ -58,7 +60,7 @@ BOOST_AUTO_TEST_CASE( getAllCategories ) BOOST_REQUIRE_EQUAL("virtual", cats.back()->name); } -BOOST_AUTO_TEST_CASE( getCategoriesInSuper ) +BOOST_AUTO_TEST_CASE(getCategoriesInSuper) { auto cats = p->getCategoriesInSuper("dev"); BOOST_REQUIRE_EQUAL(2, cats.size()); @@ -70,7 +72,7 @@ BOOST_AUTO_TEST_CASE( getCategoriesInSuper ) BOOST_REQUIRE_EQUAL(0, cats.size()); } -BOOST_AUTO_TEST_CASE( getCategoriesWithRecentAdditions ) +BOOST_AUTO_TEST_CASE(getCategoriesWithRecentAdditions) { auto cats = p->getCategoriesWithRecentAdditions(3); BOOST_REQUIRE_EQUAL(4, cats.size()); @@ -78,7 +80,7 @@ BOOST_AUTO_TEST_CASE( getCategoriesWithRecentAdditions ) BOOST_REQUIRE_EQUAL("app-backup", cats.back()->name); } -BOOST_AUTO_TEST_CASE( getAllOverviewCategories ) +BOOST_AUTO_TEST_CASE(getAllOverviewCategories) { auto cats = p->getAllOverviewCategories(); BOOST_REQUIRE_EQUAL(4, cats.size()); @@ -92,7 +94,7 @@ BOOST_AUTO_TEST_CASE( getAllOverviewCategories ) BOOST_REQUIRE_EQUAL("virtual", cats["virtual"].front()->name); } -BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) +BOOST_AUTO_TEST_CASE(getOverviewCategoriesInSuper) { auto cats = p->getOverviewCategoriesInSuper("dev"); BOOST_REQUIRE_EQUAL(2, cats.size()); @@ -107,12 +109,12 @@ BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) BOOST_REQUIRE_EQUAL(0, cats.size()); } -BOOST_AUTO_TEST_CASE( getPackageMissing ) +BOOST_AUTO_TEST_CASE(getPackageMissing) { BOOST_REQUIRE_THROW(p->getPackage(0), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getPackage ) +BOOST_AUTO_TEST_CASE(getPackage) { auto pkg = p->getPackage(53258); BOOST_REQUIRE(pkg); @@ -126,19 +128,19 @@ BOOST_AUTO_TEST_CASE( getPackage ) BOOST_REQUIRE_EQUAL("Default assignee for orphaned packages", *pkg->maintainername); } -BOOST_AUTO_TEST_CASE( findPackageMissing ) +BOOST_AUTO_TEST_CASE(findPackageMissing) { BOOST_REQUIRE_THROW(p->findPackage("not", "here"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( findPackage ) +BOOST_AUTO_TEST_CASE(findPackage) { auto pkg = p->findPackage("dev-vcs", "archway"); BOOST_REQUIRE(pkg); BOOST_REQUIRE_EQUAL(53258, pkg->packageid); } -BOOST_AUTO_TEST_CASE( getAllPackages ) +BOOST_AUTO_TEST_CASE(getAllPackages) { auto pkgs = p->getAllPackages(); BOOST_REQUIRE_EQUAL(444, pkgs.size()); @@ -146,7 +148,7 @@ BOOST_AUTO_TEST_CASE( getAllPackages ) BOOST_REQUIRE_EQUAL("vzdump", pkgs.back()->name); } -BOOST_AUTO_TEST_CASE( getPackagesInCategory ) +BOOST_AUTO_TEST_CASE(getPackagesInCategory) { auto pkgs = p->getPackagesInCategory(311); BOOST_REQUIRE_EQUAL(88, pkgs.size()); @@ -154,7 +156,7 @@ BOOST_AUTO_TEST_CASE( getPackagesInCategory ) BOOST_REQUIRE_EQUAL("veracity", pkgs.back()->name); } -BOOST_AUTO_TEST_CASE( getPackagesWithRecentAdditions ) +BOOST_AUTO_TEST_CASE(getPackagesWithRecentAdditions) { auto pkgs = p->getPackagesWithRecentAdditions(3); BOOST_REQUIRE_EQUAL(8, pkgs.size()); @@ -162,7 +164,7 @@ BOOST_AUTO_TEST_CASE( getPackagesWithRecentAdditions ) BOOST_REQUIRE_EQUAL("letsencrypt", pkgs.back()->name); } -BOOST_AUTO_TEST_CASE( getPackagesPopular ) +BOOST_AUTO_TEST_CASE(getPackagesPopular) { auto pkgs = p->getTopTrackedPackages(3); BOOST_REQUIRE_EQUAL(3, pkgs.size()); @@ -170,13 +172,13 @@ BOOST_AUTO_TEST_CASE( getPackagesPopular ) BOOST_REQUIRE_EQUAL("subversion", pkgs.back()->name); } -BOOST_AUTO_TEST_CASE( searchEmpty ) +BOOST_AUTO_TEST_CASE(searchEmpty) { auto matches = p->getPackagesSearch(""); BOOST_REQUIRE(matches.empty()); } -BOOST_AUTO_TEST_CASE( search ) +BOOST_AUTO_TEST_CASE(search) { auto matches = p->getPackagesSearch("git"); BOOST_REQUIRE_EQUAL(40, matches.size()); @@ -184,13 +186,13 @@ BOOST_AUTO_TEST_CASE( search ) BOOST_REQUIRE_CLOSE(0.72, matches.front()->rank, 1.0); } -BOOST_AUTO_TEST_CASE( searchNotFound ) +BOOST_AUTO_TEST_CASE(searchNotFound) { auto matches = p->getPackagesSearch("something that doesn't exist"); BOOST_REQUIRE(matches.empty()); } -BOOST_AUTO_TEST_CASE( getPackageVersions ) +BOOST_AUTO_TEST_CASE(getPackageVersions) { auto es = p->getPackageVersions(58252); BOOST_REQUIRE_EQUAL(9, es.size()); @@ -205,7 +207,7 @@ BOOST_AUTO_TEST_CASE( getPackageVersions ) BOOST_REQUIRE_EQUAL(629067, es.back()->ebuildid); } -BOOST_AUTO_TEST_CASE( getEbuildsByFilter ) +BOOST_AUTO_TEST_CASE(getEbuildsByFilter) { BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("dev-vcs/darcs").size(), 7); BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2").size(), 0); @@ -234,7 +236,7 @@ BOOST_AUTO_TEST_CASE( getEbuildsByFilter ) BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("dev-vcs/darcs:0").size(), 5); } -BOOST_AUTO_TEST_CASE( getPackageVersionDetails ) +BOOST_AUTO_TEST_CASE(getPackageVersionDetails) { auto es = p->getPackageVersionDetails(58252); BOOST_REQUIRE_EQUAL(9, es.size()); @@ -251,7 +253,7 @@ BOOST_AUTO_TEST_CASE( getPackageVersionDetails ) BOOST_REQUIRE_EQUAL(3, es.front()->archs.size()); } -BOOST_AUTO_TEST_CASE( getPackageChangeLog ) +BOOST_AUTO_TEST_CASE(getPackageChangeLog) { auto cl = p->getPackageChangeLog(64582); BOOST_REQUIRE_EQUAL(5, cl.size()); @@ -263,13 +265,14 @@ BOOST_AUTO_TEST_CASE( getPackageChangeLog ) BOOST_REQUIRE_EQUAL("Alexis Ballier", cl.front()->authorname); BOOST_REQUIRE_EQUAL("dev-ml/stringext: bump to 1.4.2", cl.front()->summary); BOOST_REQUIRE(cl.front()->body); - BOOST_REQUIRE_EQUAL("Package-Manager: portage-2.2.28\nSigned-off-by: Alexis Ballier <aballier@gentoo.org>", *cl.front()->body); + BOOST_REQUIRE_EQUAL( + "Package-Manager: portage-2.2.28\nSigned-off-by: Alexis Ballier <aballier@gentoo.org>", *cl.front()->body); BOOST_REQUIRE_EQUAL("2015-10-16T12:01:46", cl.back()->committime); BOOST_REQUIRE_EQUAL("tomboy64@sina.cn", cl.back()->authoremail); BOOST_REQUIRE_EQUAL("dev-ml/stringext: new ebuild", cl.back()->summary); } -BOOST_AUTO_TEST_CASE( getRecentAdditions ) +BOOST_AUTO_TEST_CASE(getRecentAdditions) { auto es = p->getRecentAdditions(2); BOOST_REQUIRE_EQUAL(8, es.size()); @@ -283,7 +286,7 @@ BOOST_AUTO_TEST_CASE( getRecentAdditions ) BOOST_REQUIRE_EQUAL("GPL-2", *es.front()->license); } -BOOST_AUTO_TEST_CASE( getPackageDependencies ) +BOOST_AUTO_TEST_CASE(getPackageDependencies) { auto d = p->getPackageDependencies(54144); BOOST_REQUIRE_EQUAL(2, d.size()); @@ -295,7 +298,7 @@ BOOST_AUTO_TEST_CASE( getPackageDependencies ) BOOST_REQUIRE_EQUAL(629007, d.back()->ebuildids.back()); } -BOOST_AUTO_TEST_CASE( getUserTrackedPackages ) +BOOST_AUTO_TEST_CASE(getUserTrackedPackages) { auto ps = p->getUserTrackedPackages(1); BOOST_REQUIRE_EQUAL(3, ps.size()); @@ -303,7 +306,7 @@ BOOST_AUTO_TEST_CASE( getUserTrackedPackages ) BOOST_REQUIRE_EQUAL(55943, ps.back()->packageid); } -BOOST_AUTO_TEST_CASE( getUserTrackedRecentVersions ) +BOOST_AUTO_TEST_CASE(getUserTrackedRecentVersions) { auto ps = p->getUserTrackedRecentVersions(1, 4); BOOST_REQUIRE_EQUAL(4, ps.size()); @@ -313,14 +316,14 @@ BOOST_AUTO_TEST_CASE( getUserTrackedRecentVersions ) BOOST_REQUIRE_EQUAL("2015-10-17T15:00:13.238126", ps.back()->firstseen); } -BOOST_AUTO_TEST_CASE( getPackageUrls ) +BOOST_AUTO_TEST_CASE(getPackageUrls) { auto urls = p->getPackageUrls(54144); BOOST_REQUIRE_EQUAL(1, urls.size()); BOOST_REQUIRE_EQUAL("http://www.git-scm.com/", urls.front()); } -BOOST_AUTO_TEST_CASE( getPackageRuntimeDependencies ) +BOOST_AUTO_TEST_CASE(getPackageRuntimeDependencies) { auto d = p->getPackageRuntimeDependencies(54144); BOOST_REQUIRE_EQUAL(3, d.size()); @@ -329,7 +332,7 @@ BOOST_AUTO_TEST_CASE( getPackageRuntimeDependencies ) BOOST_REQUIRE_EQUAL("subversion", d[2]->name); } -BOOST_AUTO_TEST_CASE( getPackagesDepending ) +BOOST_AUTO_TEST_CASE(getPackagesDepending) { auto d = p->getPackagesDepending(55923); BOOST_REQUIRE_EQUAL(6, d.size()); @@ -337,7 +340,7 @@ BOOST_AUTO_TEST_CASE( getPackagesDepending ) BOOST_REQUIRE_EQUAL("tkcvs", d.back()->name); } -BOOST_AUTO_TEST_CASE( getPackageMasks ) +BOOST_AUTO_TEST_CASE(getPackageMasks) { auto ms = p->getPackageMasks(55923); BOOST_REQUIRE_EQUAL(1, ms.size()); @@ -353,7 +356,7 @@ BOOST_AUTO_TEST_CASE( getPackageMasks ) BOOST_REQUIRE_EQUAL(629114, ms.front()->ebuildids.back()); } -BOOST_AUTO_TEST_CASE( getPackageUses ) +BOOST_AUTO_TEST_CASE(getPackageUses) { auto us = p->getPackageUses(46436); BOOST_REQUIRE_EQUAL(19, us.size()); @@ -372,7 +375,7 @@ BOOST_AUTO_TEST_CASE( getPackageUses ) BOOST_REQUIRE(!us[2]->packageid); } -BOOST_AUTO_TEST_CASE( getUseGlobalOnly ) +BOOST_AUTO_TEST_CASE(getUseGlobalOnly) { auto u = p->getUse("X"); BOOST_REQUIRE_EQUAL("X", u->use); @@ -382,12 +385,12 @@ BOOST_AUTO_TEST_CASE( getUseGlobalOnly ) BOOST_REQUIRE(!u->group); } -BOOST_AUTO_TEST_CASE( getUseMissing ) +BOOST_AUTO_TEST_CASE(getUseMissing) { BOOST_REQUIRE_THROW(p->getUse("nothing"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getUseLocalOnly ) +BOOST_AUTO_TEST_CASE(getUseLocalOnly) { auto u = p->getUse("vistafree"); BOOST_REQUIRE_EQUAL("vistafree", u->use); @@ -398,7 +401,7 @@ BOOST_AUTO_TEST_CASE( getUseLocalOnly ) BOOST_REQUIRE(!u->group); } -BOOST_AUTO_TEST_CASE( getUseLocalAndGlobal ) +BOOST_AUTO_TEST_CASE(getUseLocalAndGlobal) { auto u = p->getUse("sasl"); BOOST_REQUIRE_EQUAL("sasl", u->use); @@ -408,7 +411,7 @@ BOOST_AUTO_TEST_CASE( getUseLocalAndGlobal ) BOOST_REQUIRE(!u->group); } -BOOST_AUTO_TEST_CASE( getGlobalUses ) +BOOST_AUTO_TEST_CASE(getGlobalUses) { auto us = p->getGlobalUses(); BOOST_REQUIRE_EQUAL(393, us.size()); @@ -424,7 +427,7 @@ BOOST_AUTO_TEST_CASE( getGlobalUses ) BOOST_REQUIRE(!us.back()->group); } -BOOST_AUTO_TEST_CASE( getUsesSearch ) +BOOST_AUTO_TEST_CASE(getUsesSearch) { auto us = p->getUsesSearch("encoding"); BOOST_REQUIRE_EQUAL(4, us.size()); @@ -434,7 +437,7 @@ BOOST_AUTO_TEST_CASE( getUsesSearch ) BOOST_REQUIRE_EQUAL("Enable h264 encoding using x264", us.back()->description); } -BOOST_AUTO_TEST_CASE( getGroupUses ) +BOOST_AUTO_TEST_CASE(getGroupUses) { auto gs = p->getGroupUses("abi_x86"); BOOST_REQUIRE_EQUAL(3, gs.size()); @@ -452,7 +455,7 @@ BOOST_AUTO_TEST_CASE( getGroupUses ) BOOST_REQUIRE(!gs.back()->packageid); } -BOOST_AUTO_TEST_CASE( getUseGroups ) +BOOST_AUTO_TEST_CASE(getUseGroups) { auto gs = p->getUseGroups(); BOOST_REQUIRE_EQUAL(49, gs.size()); @@ -460,7 +463,7 @@ BOOST_AUTO_TEST_CASE( getUseGroups ) BOOST_REQUIRE_EQUAL("xtables_addons", gs.back()); } -BOOST_AUTO_TEST_CASE( getUseUsage ) +BOOST_AUTO_TEST_CASE(getUseUsage) { auto uu = p->getUseUsage("usb"); BOOST_REQUIRE_EQUAL(3, uu.size()); @@ -474,10 +477,11 @@ BOOST_AUTO_TEST_CASE( getUseUsage ) BOOST_REQUIRE(!uu.back()->isdefault); BOOST_REQUIRE(!uu.back()->group); BOOST_REQUIRE_EQUAL("usb", uu.back()->use); - BOOST_REQUIRE_EQUAL("Add USB support to applications that have optional USB support (e.g. cups)", uu.back()->description); + BOOST_REQUIRE_EQUAL( + "Add USB support to applications that have optional USB support (e.g. cups)", uu.back()->description); } -BOOST_AUTO_TEST_CASE( getUsePackages ) +BOOST_AUTO_TEST_CASE(getUsePackages) { auto ps = p->getUsePackages("usb"); BOOST_REQUIRE_EQUAL(3, ps.size()); @@ -487,12 +491,12 @@ BOOST_AUTO_TEST_CASE( getUsePackages ) BOOST_REQUIRE_EQUAL("gnupg", ps.back()->name); } -BOOST_AUTO_TEST_CASE( getBugMissing ) +BOOST_AUTO_TEST_CASE(getBugMissing) { BOOST_REQUIRE_THROW(p->getBug(10), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getBug ) +BOOST_AUTO_TEST_CASE(getBug) { auto b = p->getBug(567064); BOOST_REQUIRE(b); @@ -503,7 +507,7 @@ BOOST_AUTO_TEST_CASE( getBug ) BOOST_REQUIRE_EQUAL("Request for new package: dev-python/twine", b->summary); } -BOOST_AUTO_TEST_CASE( getPackageBugs ) +BOOST_AUTO_TEST_CASE(getPackageBugs) { auto bs = p->getPackageBugs(54654); BOOST_REQUIRE_EQUAL(1, bs.size()); @@ -511,7 +515,7 @@ BOOST_AUTO_TEST_CASE( getPackageBugs ) BOOST_REQUIRE_EQUAL("2015-12-01T20:03:52.402138", bs.front()->firstseen); } -BOOST_AUTO_TEST_CASE( getBugsSearch ) +BOOST_AUTO_TEST_CASE(getBugsSearch) { auto bs = p->getBugsSearch("cpu"); BOOST_REQUIRE_EQUAL(3, bs.size()); @@ -522,12 +526,12 @@ BOOST_AUTO_TEST_CASE( getBugsSearch ) BOOST_REQUIRE_EQUAL(567682, bs[2]->bugid); } -BOOST_AUTO_TEST_CASE( getNewsItemMissing ) +BOOST_AUTO_TEST_CASE(getNewsItemMissing) { BOOST_REQUIRE_THROW(p->getNewsItem("2015-02-02-use-libav"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getNewsItem ) +BOOST_AUTO_TEST_CASE(getNewsItem) { auto n = p->getNewsItem("2015-02-01-use-libav"); BOOST_REQUIRE(n); @@ -542,8 +546,17 @@ BOOST_AUTO_TEST_CASE( getNewsItem ) BOOST_REQUIRE_EQUAL("media-video/ffmpeg", n->atomspec.front()); BOOST_REQUIRE_EQUAL("media-video/libav", n->atomspec.back()); BOOST_REQUIRE_EQUAL(5, n->body.size()); - BOOST_REQUIRE_EQUAL("The support for automatic choice between ffmpeg and libav is going to be deprecated in favor of explicit choice via USE flags. This change aims to solve multiple repeating issues, including Portage undesirably wanting to replace one package with the other, lack of proper reverse dependency on ffmpeg/libav upgrades and some of the hard-to-understand upgrade failures involving blockers. It also may be used to make ffmpeg and libav co-installable in the future.", n->body.front()); - BOOST_REQUIRE_EQUAL("Please do not alter the state of 'libav' flag on a per-package basis (e.g. via package.use). The flag needs to be set globally to have consistent value throughout all packages. Otherwise, blockers will prevent upgrades.", n->body.back()); + BOOST_REQUIRE_EQUAL( + "The support for automatic choice between ffmpeg and libav is going to be deprecated in favor of explicit " + "choice via USE flags. This change aims to solve multiple repeating issues, including Portage undesirably " + "wanting to replace one package with the other, lack of proper reverse dependency on ffmpeg/libav upgrades " + "and some of the hard-to-understand upgrade failures involving blockers. It also may be used to make " + "ffmpeg and libav co-installable in the future.", + n->body.front()); + BOOST_REQUIRE_EQUAL("Please do not alter the state of 'libav' flag on a per-package basis (e.g. via package.use). " + "The flag needs to be set globally to have consistent value throughout all packages. " + "Otherwise, blockers will prevent upgrades.", + n->body.back()); BOOST_REQUIRE_EQUAL(0, n->urls.size()); auto n2 = p->getNewsItem("2014-10-26-gcc_4_7_introduced_new_c++11_abi"); @@ -553,17 +566,21 @@ BOOST_AUTO_TEST_CASE( getNewsItem ) BOOST_REQUIRE_EQUAL("http://ispras.linuxbase.org/index.php/ABI_compliance_checker", n2->urls.front()); } -BOOST_AUTO_TEST_CASE( getNewsSearch ) +BOOST_AUTO_TEST_CASE(getNewsSearch) { auto ns = p->getNewsSearch("gcc"); BOOST_REQUIRE_EQUAL(5, ns.size()); - BOOST_REQUIRE_EQUAL("Or you might see linkage failures with \"std::__cxx11::string\" in the output.", ns.front()->body[1]); - BOOST_REQUIRE_EQUAL("These are signs that you need to rebuild packages using the new C++ ABI. You can quickly do so by using revdep-rebuild (from gentoolkit) like so: # revdep-rebuild --library 'libstdc\\+\\+\\.so\\.6' -- --exclude gcc", ns.front()->body[2]); + BOOST_REQUIRE_EQUAL( + "Or you might see linkage failures with \"std::__cxx11::string\" in the output.", ns.front()->body[1]); + BOOST_REQUIRE_EQUAL("These are signs that you need to rebuild packages using the new C++ ABI. You can quickly do " + "so by using revdep-rebuild (from gentoolkit) like so: # revdep-rebuild --library " + "'libstdc\\+\\+\\.so\\.6' -- --exclude gcc", + ns.front()->body[2]); BOOST_REQUIRE_EQUAL("2015-10-22", ns.front()->posted); BOOST_REQUIRE_EQUAL("2009-01-04", ns.back()->posted); } -BOOST_AUTO_TEST_CASE( getNewsRecent ) +BOOST_AUTO_TEST_CASE(getNewsRecent) { auto ns = p->getNewsRecent(3); BOOST_REQUIRE_EQUAL(3, ns.size()); @@ -571,7 +588,7 @@ BOOST_AUTO_TEST_CASE( getNewsRecent ) BOOST_REQUIRE_EQUAL("2015-10-07", ns.back()->posted); } -BOOST_AUTO_TEST_CASE( getRepository ) +BOOST_AUTO_TEST_CASE(getRepository) { auto r = p->getRepository(17); BOOST_REQUIRE_EQUAL(17, r.repoid); @@ -582,12 +599,12 @@ BOOST_AUTO_TEST_CASE( getRepository ) BOOST_REQUIRE_EQUAL("87ebb8523b2890c641a27f29007ba8eaa6aa834e", r.lastcommit); } -BOOST_AUTO_TEST_CASE( getRepositoryMissing ) +BOOST_AUTO_TEST_CASE(getRepositoryMissing) { BOOST_REQUIRE_THROW(p->getRepository(1), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getRepositories ) +BOOST_AUTO_TEST_CASE(getRepositories) { auto rs = p->getRepositories(); BOOST_REQUIRE_EQUAL(2, rs.size()); @@ -603,4 +620,3 @@ BOOST_AUTO_TEST_CASE( getRepositories ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/gentoobrowse-api/unittests/testProcessAll.cpp b/gentoobrowse-api/unittests/testProcessAll.cpp index b3c2d77..32f0b70 100644 --- a/gentoobrowse-api/unittests/testProcessAll.cpp +++ b/gentoobrowse-api/unittests/testProcessAll.cpp @@ -1,11 +1,11 @@ #define BOOST_TEST_MODULE TestProcessAll -#include <boost/test/unit_test.hpp> #include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> #include <depend.h> +#include <filesystem> #include <news.h> #include <utils/ebuildCacheParser.h> -#include <filesystem> void testDependRange(const std::optional<std::string_view> & r) @@ -16,18 +16,17 @@ testDependRange(const std::optional<std::string_view> & r) } auto -getFileList(const std::filesystem::path & root, bool(*pred)(const std::filesystem::path &)) +getFileList(const std::filesystem::path & root, bool (*pred)(const std::filesystem::path &)) { std::vector<std::filesystem::path> paths; - std::copy_if(std::filesystem::recursive_directory_iterator(root), - std::filesystem::recursive_directory_iterator(), + std::copy_if(std::filesystem::recursive_directory_iterator(root), std::filesystem::recursive_directory_iterator(), std::back_inserter(paths), pred); return paths; } -BOOST_DATA_TEST_CASE( ebuildCacheDependencies, boost::unit_test::data::make( - getFileList("/usr/portage/metadata/md5-cache", std::filesystem::is_regular_file)), - path ) +BOOST_DATA_TEST_CASE(ebuildCacheDependencies, + boost::unit_test::data::make(getFileList("/usr/portage/metadata/md5-cache", std::filesystem::is_regular_file)), + path) { Gentoo::Utils::EbuildCacheParser ecp(path); testDependRange(ecp.getRange("DEPEND")); @@ -35,9 +34,8 @@ BOOST_DATA_TEST_CASE( ebuildCacheDependencies, boost::unit_test::data::make( testDependRange(ecp.getRange("PDEPEND")); } -BOOST_DATA_TEST_CASE( news, boost::unit_test::data::make( - getFileList("/usr/portage/metadata/news", std::filesystem::is_regular_file)), - path ) +BOOST_DATA_TEST_CASE(news, + boost::unit_test::data::make(getFileList("/usr/portage/metadata/news", std::filesystem::is_regular_file)), path) { AdHoc::FileUtils::MemMap n(path); auto news = Portage::Utils::News::parse(n.sv<gchar>()); @@ -51,4 +49,3 @@ BOOST_DATA_TEST_CASE( news, boost::unit_test::data::make( BOOST_CHECK_EQUAL(news->posted.length(), 10); BOOST_CHECK(news->newsid.empty()); // From file name, not handled by parser } - diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp index e3fb3c9..51ddb08 100644 --- a/gentoobrowse-api/unittests/testUsers.cpp +++ b/gentoobrowse-api/unittests/testUsers.cpp @@ -4,11 +4,11 @@ #include "mockDefs.h" #include <mockMailServer.h> -BOOST_GLOBAL_FIXTURE( Service ); +BOOST_GLOBAL_FIXTURE(Service); BOOST_FIXTURE_TEST_SUITE(tp, TestClient) -BOOST_AUTO_TEST_CASE( authenticateGood ) +BOOST_AUTO_TEST_CASE(authenticateGood) { auto user = u->authenticate("randomdan", "p@55w0rd"); BOOST_REQUIRE_EQUAL(1, user->userid); @@ -17,22 +17,22 @@ BOOST_AUTO_TEST_CASE( authenticateGood ) BOOST_REQUIRE_EQUAL("dan@randomdan.homeip.net", user->useremail); } -BOOST_AUTO_TEST_CASE( authenticateBad ) +BOOST_AUTO_TEST_CASE(authenticateBad) { BOOST_REQUIRE_THROW(u->authenticate("bad", "login"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( authenticateUnverified ) +BOOST_AUTO_TEST_CASE(authenticateUnverified) { BOOST_REQUIRE_THROW(u->authenticate("unverified", "p@55w0rd"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( authenticateVerifyBad ) +BOOST_AUTO_TEST_CASE(authenticateVerifyBad) { BOOST_REQUIRE_THROW(u->verify("unverified", "c2075a2e-8a45-11e6-bb50-c86000a60e12"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( authenticateVerify ) +BOOST_AUTO_TEST_CASE(authenticateVerify) { auto verified = u->verify("unverified", "a24eb4fa-8a42-11e6-a04e-c86000a60e12"); BOOST_REQUIRE(verified); @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( authenticateVerify ) BOOST_REQUIRE_THROW(u->verify("unverified", "a24eb4fa-8a42-11e6-a04e-c86000a60e12"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( create ) +BOOST_AUTO_TEST_CASE(create) { auto ms1 = IceTray::Cube::get<IceTray::Mail::MailServer>(); BOOST_REQUIRE(ms1); @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE( create ) BOOST_REQUIRE_EQUAL(36, user->verifyguid.length()); } -BOOST_AUTO_TEST_CASE( get ) +BOOST_AUTO_TEST_CASE(get) { auto user = u->get(1); BOOST_REQUIRE(user); @@ -74,13 +74,13 @@ BOOST_AUTO_TEST_CASE( get ) BOOST_REQUIRE(!user->lastmailshot); } -BOOST_AUTO_TEST_CASE( getNotVerified ) +BOOST_AUTO_TEST_CASE(getNotVerified) { // Is not verified, doesn't exist BOOST_REQUIRE_THROW(u->get(4), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( getNew ) +BOOST_AUTO_TEST_CASE(getNew) { auto user = u->getNew("testuser", "testpass"); BOOST_REQUIRE(user); @@ -93,13 +93,13 @@ BOOST_AUTO_TEST_CASE( getNew ) BOOST_REQUIRE(!user->lastmailshot); } -BOOST_AUTO_TEST_CASE( getNewVerified ) +BOOST_AUTO_TEST_CASE(getNewVerified) { // Is verified, not new BOOST_REQUIRE_THROW(u->getNew("randomdan", "p@55w0rd"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( createAgain ) +BOOST_AUTO_TEST_CASE(createAgain) { /* * Should (unverified): @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE( createAgain ) BOOST_REQUIRE_EQUAL(36, user->verifyguid.length()); } -BOOST_AUTO_TEST_CASE( prune ) +BOOST_AUTO_TEST_CASE(prune) { BOOST_REQUIRE(u->get(1)); // Verified BOOST_REQUIRE(u->getNew("dontverify", "p@55w0rd")); // Old, not verified @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( prune ) BOOST_REQUIRE(u->getNew("testuser", "testpass")); // Not delete; New, not verified } -BOOST_AUTO_TEST_CASE( verify ) +BOOST_AUTO_TEST_CASE(verify) { auto user = u->getNew("testuser", "testpass"); BOOST_REQUIRE(user); @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE( verify ) BOOST_REQUIRE(u->get(4)); } -BOOST_AUTO_TEST_CASE( sendmailshot ) +BOOST_AUTO_TEST_CASE(sendmailshot) { auto user = u->get(4); BOOST_REQUIRE(user); @@ -154,12 +154,12 @@ BOOST_AUTO_TEST_CASE( sendmailshot ) BOOST_REQUIRE_GE(user->lastmailshot->length(), 19); } -BOOST_AUTO_TEST_CASE( getMissing ) +BOOST_AUTO_TEST_CASE(getMissing) { BOOST_REQUIRE_THROW(u->get(20), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( find ) +BOOST_AUTO_TEST_CASE(find) { auto user = u->find("testuser"); BOOST_REQUIRE_EQUAL(4, user->userid); @@ -168,12 +168,12 @@ BOOST_AUTO_TEST_CASE( find ) BOOST_REQUIRE_EQUAL("test@user.com", user->useremail); } -BOOST_AUTO_TEST_CASE( findMissing ) +BOOST_AUTO_TEST_CASE(findMissing) { BOOST_REQUIRE_THROW(u->find("nobody"), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( deleteCheck ) +BOOST_AUTO_TEST_CASE(deleteCheck) { u->get(4); u->remove(3, "wrongpass"); @@ -182,22 +182,21 @@ BOOST_AUTO_TEST_CASE( deleteCheck ) BOOST_REQUIRE_THROW(u->get(4), Slicer::NoRowsReturned); } -BOOST_AUTO_TEST_CASE( track ) +BOOST_AUTO_TEST_CASE(track) { u->track(1, 44473); } -BOOST_AUTO_TEST_CASE( tracked ) +BOOST_AUTO_TEST_CASE(tracked) { auto ids = u->tracked(1); BOOST_REQUIRE_EQUAL(4, ids.size()); BOOST_REQUIRE_EQUAL(44473, ids.front()); } -BOOST_AUTO_TEST_CASE( untrack ) +BOOST_AUTO_TEST_CASE(untrack) { u->untrack(1, 44473); } BOOST_AUTO_TEST_SUITE_END() - diff --git a/gentoobrowse-api/unittests/testUtils.cpp b/gentoobrowse-api/unittests/testUtils.cpp index bd601d9..6d66de5 100644 --- a/gentoobrowse-api/unittests/testUtils.cpp +++ b/gentoobrowse-api/unittests/testUtils.cpp @@ -1,22 +1,20 @@ #define BOOST_TEST_MODULE TestDepend #include <boost/test/unit_test.hpp> -#include <utils/git.h> +#include <definedDirs.h> #include <libxml/parser.h> #include <maintenance.h> #include <utils/ebuildCacheParser.h> -#include <definedDirs.h> +#include <utils/git.h> using namespace Gentoo::Utils::Git; -BOOST_AUTO_TEST_CASE( gitErrorMessage ) +BOOST_AUTO_TEST_CASE(gitErrorMessage) { xmlInitParser(); git_libgit2_init(); - BOOST_REQUIRE_THROW( - gitSafeGet(git_repository_open_ext, git_repository_free, "/", 0, nullptr), - Gentoo::GitError); + BOOST_REQUIRE_THROW(gitSafeGet(git_repository_open_ext, git_repository_free, "/", 0, nullptr), Gentoo::GitError); try { gitSafeGet(git_repository_open_ext, git_repository_free, "/", 0, nullptr); @@ -34,7 +32,7 @@ BOOST_AUTO_TEST_CASE( gitErrorMessage ) git_libgit2_shutdown(); } -BOOST_AUTO_TEST_CASE( EbuildCacheParser ) +BOOST_AUTO_TEST_CASE(EbuildCacheParser) { Gentoo::Utils::EbuildCacheParser ecp(rootDir / "fixtures" / "accerciser-3.22.0"); BOOST_REQUIRE(!ecp.get("missing")); @@ -42,4 +40,3 @@ BOOST_AUTO_TEST_CASE( EbuildCacheParser ) BOOST_REQUIRE_EQUAL("0", *ecp.get("SLOT")); BOOST_REQUIRE_EQUAL("d824645ab9e59e46288f40f698baa5e7", *ecp.get("_md5_")); } - diff --git a/gentoobrowse-api/util/update.cpp b/gentoobrowse-api/util/update.cpp index 4c4b1dd..ab4d2a5 100644 --- a/gentoobrowse-api/util/update.cpp +++ b/gentoobrowse-api/util/update.cpp @@ -1,6 +1,6 @@ -#include <maintenance.h> #include <Ice/Ice.h> #include <boost/program_options.hpp> +#include <maintenance.h> namespace po = boost::program_options; @@ -10,15 +10,12 @@ main(int c, char ** v) std::string endpoint; bool background, tree, bugs, sendNotifications, pull; po::options_description opts("Gentoo Browse Util::Update options"); - opts.add_options() - ("endpoint", po::value(&endpoint)->default_value("tcp -p 9001"), "Service endpoint") - ("background,b", po::value(&background)->default_value(false)->zero_tokens(), "Background") - ("bugs", po::value(&bugs)->default_value(true), "Update bugs") - ("tree", po::value(&tree)->default_value(true), "Update tree") - ("pull", po::value(&pull)->default_value(true), "Perform a git pull on repositories") - ("notifications", po::value(&sendNotifications)->default_value(true), "Send notification emails") - ("help,h", "Show help") - ; + opts.add_options()("endpoint", po::value(&endpoint)->default_value("tcp -p 9001"), "Service endpoint")( + "background,b", po::value(&background)->default_value(false)->zero_tokens(), "Background")("bugs", + po::value(&bugs)->default_value(true), + "Update bugs")("tree", po::value(&tree)->default_value(true), "Update tree")( + "pull", po::value(&pull)->default_value(true), "Perform a git pull on repositories")("notifications", + po::value(&sendNotifications)->default_value(true), "Send notification emails")("help,h", "Show help"); po::variables_map vm; po::store(po::command_line_parser(c, v).options(opts).run(), vm); @@ -34,21 +31,24 @@ main(int c, char ** v) m->ice_ping(); std::vector<std::future<void>> jobs; - if (bugs) jobs.push_back(m->refreshBugsAsync()); - if (pull) m->updateRepositories(); - if (tree) jobs.push_back(m->refreshPackageTreeAsync()); + if (bugs) + jobs.push_back(m->refreshBugsAsync()); + if (pull) + m->updateRepositories(); + if (tree) + jobs.push_back(m->refreshPackageTreeAsync()); int failures = 0; if (!background) { std::for_each(jobs.begin(), jobs.end(), [&failures](auto & f) { - try { - f.get(); - } - catch (const std::exception & ex) { - failures += 1; - std::cerr << ex.what() << std::endl; - } - }); + try { + f.get(); + } + catch (const std::exception & ex) { + failures += 1; + std::cerr << ex.what() << std::endl; + } + }); if (sendNotifications) { m->sendNotifications(); } @@ -58,4 +58,3 @@ main(int c, char ** v) ic->destroy(); return failures; } - |