From 2f84b12515ceaeda7944e8a84f00778bb64cb86d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 15 Dec 2020 02:21:40 +0000 Subject: Clang format --- gentoobrowse-api/api/impl.cpp | 6 +- gentoobrowse-api/client/helpers.h | 13 +- gentoobrowse-api/client/main.cpp | 17 +- gentoobrowse-api/client/main.h | 9 +- gentoobrowse-api/client/search.cpp | 31 +- gentoobrowse-api/domain/converters.cpp | 14 +- gentoobrowse-api/domain/converters.h | 22 +- gentoobrowse-api/domain/converters.impl.h | 28 +- gentoobrowse-api/domain/unpackPqTextArray.h | 22 +- gentoobrowse-api/etc/icebox.config | 10 +- gentoobrowse-api/etc/service.conf | 5 +- gentoobrowse-api/service/changeSet.h | 5 +- gentoobrowse-api/service/depend.cpp | 96 ++-- gentoobrowse-api/service/depend.h | 17 +- gentoobrowse-api/service/main.cpp | 73 +-- .../service/maintenance/abstractFileProcessor.cpp | 5 +- .../service/maintenance/abstractFileProcessor.h | 41 +- .../service/maintenance/categoryMetaProcessor.cpp | 32 +- .../service/maintenance/categoryMetaProcessor.h | 17 +- .../service/maintenance/ebuildMetaProcessor.cpp | 134 ++--- .../service/maintenance/ebuildMetaProcessor.h | 62 +-- .../service/maintenance/masksProcessor.cpp | 93 ++-- .../service/maintenance/masksProcessor.h | 21 +- .../service/maintenance/newsProcessor.cpp | 29 +- .../service/maintenance/newsProcessor.h | 23 +- .../service/maintenance/packageMetaProcessor.cpp | 33 +- .../service/maintenance/packageMetaProcessor.h | 17 +- .../service/maintenance/updatesProcessor.cpp | 178 ++++--- .../service/maintenance/updatesProcessor.h | 36 +- .../service/maintenance/useGlobalProcessor.cpp | 35 +- .../service/maintenance/useGlobalProcessor.h | 19 +- .../service/maintenance/useGroupProcessor.cpp | 56 +- .../service/maintenance/useGroupProcessor.h | 23 +- .../service/maintenance/useLocalProcessor.cpp | 45 +- .../service/maintenance/useLocalProcessor.h | 19 +- gentoobrowse-api/service/maintenanceBugs.cpp | 106 ++-- gentoobrowse-api/service/maintenanceCommon.cpp | 100 ++-- .../service/maintenanceGitOperations.cpp | 98 ++-- gentoobrowse-api/service/maintenanceimpl.h | 49 +- gentoobrowse-api/service/mask.cpp | 53 +- gentoobrowse-api/service/mask.h | 19 +- gentoobrowse-api/service/news.cpp | 134 +++-- gentoobrowse-api/service/news.h | 15 +- .../service/notifications/css/style.css | 302 +++++++++-- gentoobrowse-api/service/notificationsimpl.cpp | 23 +- gentoobrowse-api/service/notificationsimpl.h | 23 +- gentoobrowse-api/service/portageimpl.cpp | 580 ++++++++++----------- gentoobrowse-api/service/portageimpl.h | 102 ++-- gentoobrowse-api/service/usersimpl.cpp | 250 +++++---- gentoobrowse-api/service/usersimpl.h | 53 +- gentoobrowse-api/service/utils/dbUtils.cpp | 21 +- gentoobrowse-api/service/utils/dbUtils.h | 13 +- .../service/utils/ebuildCacheParser.cpp | 6 +- gentoobrowse-api/service/utils/ebuildCacheParser.h | 21 +- .../service/utils/entityWhereFilter.cpp | 13 +- gentoobrowse-api/service/utils/entityWhereFilter.h | 24 +- gentoobrowse-api/service/utils/git.cpp | 17 +- gentoobrowse-api/service/utils/git.h | 27 +- .../service/utils/splitEbuildProps.cpp | 13 +- gentoobrowse-api/service/utils/splitEbuildProps.h | 18 +- gentoobrowse-api/service/utils/xmlUtils.cpp | 6 +- gentoobrowse-api/service/utils/xmlUtils.h | 9 +- gentoobrowse-api/service/xsltStreamSerializer.cpp | 50 +- gentoobrowse-api/service/xsltStreamSerializer.h | 25 +- gentoobrowse-api/unittests/mockDefs.cpp | 36 +- gentoobrowse-api/unittests/mockDefs.h | 59 ++- gentoobrowse-api/unittests/testBugs.cpp | 5 +- gentoobrowse-api/unittests/testDepend.cpp | 68 +-- gentoobrowse-api/unittests/testMaintenance.cpp | 226 ++++---- gentoobrowse-api/unittests/testMaintenanceBits.cpp | 9 +- gentoobrowse-api/unittests/testMasks.cpp | 47 +- gentoobrowse-api/unittests/testNews.cpp | 23 +- gentoobrowse-api/unittests/testNotifications.cpp | 86 +-- .../unittests/testNotificationsTriggers.cpp | 19 +- gentoobrowse-api/unittests/testPerf.cpp | 18 +- gentoobrowse-api/unittests/testPortage.cpp | 144 ++--- gentoobrowse-api/unittests/testProcessAll.cpp | 21 +- gentoobrowse-api/unittests/testUsers.cpp | 45 +- gentoobrowse-api/unittests/testUtils.cpp | 13 +- gentoobrowse-api/util/update.cpp | 43 +- 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 #include +#include 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 #include +#include +#include +#include #include template std::map -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 (Proxy::element_type::*b)(Key, const ::Ice::Context &)) { std::map 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 -#include +#include "stdio.h" #include #include +#include +#include namespace po = boost::program_options; INSTANTIATEPLUGINOF(Module); @@ -15,12 +15,10 @@ main(int c, char ** v) std::string module; std::vector 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 -#include #include #include +#include +#include class Module : public AdHoc::AbstractPluginImplementation { - public: - virtual void run(const Gentoo::PortagePrxPtr &, const std::vector &) const = 0; +public: + virtual void run(const Gentoo::PortagePrxPtr &, const std::vector &) 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 -#include -#include -#include "main.h" #include "helpers.h" +#include "main.h" +#include +#include +#include class search : public Module { - public: - void run(const Gentoo::PortagePrxPtr & p, const std::vector & a) const override - { - auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); - auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, - (std::future (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 & a) const override + { + auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); + auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, + (std::future(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 #include "converters.h" #include "converters.impl.h" #include "unpackPqTextArray.h" -#include #include #include +#include +#include namespace Slicer { - template - PqArray::PqArray(std::vector * l) : - ModelPartForSequence>(l) - { - } + template PqArray::PqArray(std::vector * l) : ModelPartForSequence>(l) { } template - void PqArray::SetValue(ValueSource && s) + void + PqArray::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 #include -#include +#include #include +#include namespace Slicer { - template - class DLL_PUBLIC PqArray : public ModelPartForSequence> { - public: - PqArray(std::vector *); + template class DLL_PUBLIC PqArray : public ModelPartForSequence> { + public: + PqArray(std::vector *); - 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 namespace Slicer { - template - class UnpackPqTextArrayInto : public UnpackPqTextArray { - public: - UnpackPqTextArrayInto(std::istream & s, std::vector & l) : - UnpackPqTextArray(s), - list(l) - { - } + template class UnpackPqTextArrayInto : public UnpackPqTextArray { + public: + UnpackPqTextArrayInto(std::istream & s, std::vector & l) : UnpackPqTextArray(s), list(l) { } - virtual void consume(const std::string & s) override - { - list.push_back(boost::lexical_cast(s)); - } + virtual void + consume(const std::string & s) override + { + list.push_back(boost::lexical_cast(s)); + } - private: - std::vector & list; + private: + std::vector & list; }; std::string @@ -45,7 +42,7 @@ namespace Slicer { } } - template + template std::vector 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 #ifndef yyFlexLexer -#define yyFlexLexer pqBaseFlexLexer -#include +# define yyFlexLexer pqBaseFlexLexer +# include #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 -#include #include +#include #include +#include 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 #include -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 Ice::optional iuo(const std::optional & x) + template + Ice::optional + iuo(const std::optional & x) { if (x) { return Ice::optional(*x); @@ -28,53 +33,59 @@ namespace Portage { return Ice::optional(); } - template std::vector split(const std::optional & x) + template + std::vector + split(const std::optional & x) { std::vector 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( - when, - iuo(es->pattern()->match(1)), // op - *es->pattern()->match(2), // category - *es->pattern()->match(3), // package - iuo(es->pattern()->match(5)), // version - iuo(es->pattern()->match(11)), // slot - split(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(when, + iuo(es->pattern()->match(1)), // op + *es->pattern()->match(2), // category + *es->pattern()->match(3), // package + iuo(es->pattern()->match(5)), // version + iuo(es->pattern()->match(11)), // slot + split(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 -#include -#include #include +#include +#include namespace Portage { namespace Utils { class Depend : AdHoc::Lexer { - private: - Depend(); - Gentoo::StringList when; + private: + Depend(); + Gentoo::StringList when; - public: - static std::vector parse(const std::string_view &); - std::vector ds; + public: + static std::vector parse(const std::string_view &); + std::vector 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 -#include -#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 #include +#include +#include #include #include -#include 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(adp, "portage", db); - IceTray::Cube::addObject(adp, "maintenance", db, ic, props); - IceTray::Cube::addObject(adp, "users", db); - IceTray::Cube::add(); - IceTray::Cube::add( - 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(adp, "portage", db); + IceTray::Cube::addObject(adp, "maintenance", db, ic, props); + IceTray::Cube::addObject(adp, "users", db); + IceTray::Cube::add(); + IceTray::Cube::add( + 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 -#include -#include #include -#include "changeSet.h" +#include +#include namespace Gentoo { namespace Service { typedef std::vector 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 FileProcessorPtr; typedef AdHoc::Factory 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 +#include "utils/dbUtils.h" +#include "utils/xmlUtils.h" #include +#include #include -#include "utils/xmlUtils.h" -#include "utils/dbUtils.h" #include 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 -#include -#include -#include -#include -#include -#include -#include -#include #include "depend.h" #include "utils/dbUtils.h" #include "utils/ebuildCacheParser.h" #include "utils/splitEbuildProps.h" +#include +#include +#include +#include +#include +#include #include -#include -#include -#include #include -#include -#include +#include #include #include +#include #include +#include #include -#include +#include +#include +#include +#include +#include namespace U = Gentoo::Utils; using namespace AdHoc; @@ -33,20 +32,27 @@ static Glib::RefPtr 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([this,dbc,&ecp] (auto ebuildId, auto newest, auto packageId) { - this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); - }); + m->forEachRow([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([this,dbc,&ecp] (auto ebuildId, auto newest, auto packageId) { - this->perEbuildUpdates(dbc, ecp, ebuildId, newest, packageId); - }); + m->forEachRow([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 - const T & operator|=(const IceUtil::Optional & a, const T & b) + const T & + operator|=(const IceUtil::Optional & 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 +#include "utils/entityWhereFilter.h" #include -#include #include -#include "utils/entityWhereFilter.h" +#include +#include 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 &); - - DB::ModifyCommandPtr depInsert; - DB::ModifyCommandPtr useInsert; - DB::ModifyCommandPtr archInsert; - Utils::EntityWhereFilter ebuildIds; - typedef std::pair CategoryPackage; - typedef std::set 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 &); + + DB::ModifyCommandPtr depInsert; + DB::ModifyCommandPtr useInsert; + DB::ModifyCommandPtr archInsert; + Utils::EntityWhereFilter ebuildIds; + typedef std::pair CategoryPackage; + typedef std::set 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 +#include "sql/maintenance/masksEbuilds.sql.h" +#include "sql/maintenance/masksFixDates.sql.h" +#include "sql/maintenance/masksSets.sql.h" +#include "utils/dbUtils.h" #include +#include +#include +#include +#include #include #include #include -#include "utils/dbUtils.h" -#include -#include -#include -#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 -#include #include +#include 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 #include "news.h" -#include -#include +#include #include #include +#include +#include +#include #include -#include 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(dbc, path); } - template + template 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 - static void importNews(DB::Connection * dbc, const std::filesystem::path & path); + private: + template + 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 #include #include -#include -#include "utils/xmlUtils.h" -#include "utils/dbUtils.h" #include 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 -#include -#include -#include #include "utils/dbUtils.h" #include "utils/entityWhereFilter.h" -#include +#include +#include +#include #include +#include +#include +#include #include #include #include #include -#include -#include +#include using namespace AdHoc::FileUtils; -static Glib::RefPtr move = Glib::Regex::create( - R"R(^move ([^/]+)/([^ ]+) ([^/]+)/(.+)$)R", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr 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 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([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 updatePacks; + + void + move(DB::SelectCommandPtr s) + { + s->forEachRow( + [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(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 -#include #include +#include 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 -#include -#include #include "utils/dbUtils.h" +#include #include +#include +#include using namespace AdHoc::FileUtils; -static Glib::RefPtr useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr 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(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 -#include #include +#include 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 -#include -#include -#include -#include "utils/dbUtils.h" -#include "utils/entityWhereFilter.h" -#include #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 +#include +#include +#include +#include +#include namespace U = Gentoo::Utils; -static Glib::RefPtr useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr 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([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([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 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 -#include #include +#include 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 +#include #include #include #include -#include -#include "utils/dbUtils.h" -#include -#include "sql/maintenance/useLocalMap.sql.h" using namespace AdHoc::FileUtils; -static Glib::RefPtr useDesc = Glib::Regex::create("^([^#\\s][^/]*)/([^:]+):([^ ]+)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); +static Glib::RefPtr 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(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 -#include #include +#include 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 #include -#include -#include +#include #include -#include -#include #include -#include -#include +#include +#include #include #include +#include +#include +#include +#include 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(*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(*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 stk; + private: + DB::ModifyCommandPtr ins; + std::stack 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(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(IceTray::Logging::LogLevel::INFO, result.inserts, result.updates, result.deletes); + log->messagectf( + 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 +#include "sql/maintenance/getNotificationEbuildLists.sql.h" #include +#include +#include #include #include -#include #include -#include -#include "sql/maintenance/getNotificationEbuildLists.sql.h" +#include 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(); - 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(); + 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(); - u->prune(); - } + public: + UserMaintenance(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { } + + void + runTimerTask() override + { + auto u = IceTray::Cube::get(); + 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(ic, p, "SyncTime"); addTask(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(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 +#include "utils/git.h" #include +#include #include -#include -#include +#include #include +#include +#include +#include +#include #include -#include -#include #include -#include -#include "utils/git.h" -#include "converters.impl.h" -#include +#include +#include #include -#include -#include +#include namespace Gentoo { namespace Service { @@ -24,8 +24,7 @@ namespace Gentoo { typedef std::set StringSet; - static - int + static int onFile(const git_diff_delta * delta, void * fileset) { static_cast(fileset)->insert(delta->old_file.path); @@ -34,8 +33,7 @@ namespace Gentoo { } template - 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(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 parentTree(nullptr, git_tree_free); + std::unique_ptr 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, onFile, nullptr, nullptr, &fs); + gitSafe(git_diff_foreach, diff.get(), onFile, onFile, 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(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 - 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(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, insertFileChangeT, nullptr, nullptr, &changes); + gitSafe(git_diff_foreach, diff.get(), insertFileChangeT, insertFileChangeT, + 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(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(IceTray::Logging::LogLevel::DEBUG); @@ -201,13 +200,16 @@ namespace Gentoo { std::map> fps; for (const auto & fpf : AdHoc::PluginManager::getDefault()->getAll()) { 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 FileHandleFunc; + typedef std::function + FileHandleFunc; std::map 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 -#include -#include +#include #include -#include #include -#include "maintenance/abstractFileProcessor.h" -#include -#include "changeSet.h" +#include +#include +#include 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 - void addTask(Ice::CommunicatorPtr ic, Ice::PropertiesPtr p, const std::string & whenCfg); + private: + template + 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 - static FileProcessorPtr createFileProessor(); - IceUtil::TimerPtr taskRunner; + template 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 #include +#include 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 #include #include -#include #include 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 person, email; - std::set atoms; - std::list message; - int n; + Glib::ustring date; + std::optional person, email; + std::set atoms; + std::list 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 #include -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 Ice::optional iuo(const std::optional & x) + template + Ice::optional + iuo(const std::optional & x) { if (x) { return Ice::optional(*x); @@ -23,59 +33,68 @@ namespace Portage { return Ice::optional(); } - template std::vector split(const std::optional & x) + template + std::vector + split(const std::optional & x) { std::vector 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 - { { 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 + {{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()) { } @@ -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 -#include -#include #include +#include +#include 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 &); + public: + Gentoo::NewsItemPtr news; + static Gentoo::NewsItemPtr parse(const std::basic_string_view &); }; } } #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 #include #include #include -#include #include -#include "xsltStreamSerializer.h" +#include 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(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(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(); 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 +#include #include #include -#include -#include 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 xsltSSPtr; - xsltSSPtr news; - xsltSSPtr signup; + typedef std::shared_ptr 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 #include +#include #include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include #include -#include -#include #include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include #include -#include #include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include 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(sql::portage::getCategory, 30, id); -} - -Gentoo::CategoryPtr -Portage::findCategory(const std::string_view name, const Ice::Current &) -{ - return fetchCache(sql::portage::findCategory, 30, name); -} - -Gentoo::Categories -Portage::getAllCategories(const Ice::Current &) -{ - return fetchCache(sql::portage::getAllCategories, 30); -} - -Gentoo::Categories -Portage::getCategoriesInSuper(const std::string_view super, const Ice::Current &) -{ - return fetchCache(sql::portage::getCategoriesInSuper, 30, super); -} - -Gentoo::OverviewCategoriesBySuper -Portage::getAllOverviewCategories(const Ice::Current &) -{ - Gentoo::OverviewCategoriesBySuper rtn; - auto cats = fetchCache(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(sql::portage::getCategory, 30, id); + } + + Gentoo::CategoryPtr + Portage::findCategory(const std::string_view name, const Ice::Current &) + { + return fetchCache(sql::portage::findCategory, 30, name); + } + + Gentoo::Categories + Portage::getAllCategories(const Ice::Current &) + { + return fetchCache(sql::portage::getAllCategories, 30); + } + + Gentoo::Categories + Portage::getCategoriesInSuper(const std::string_view super, const Ice::Current &) + { + return fetchCache(sql::portage::getCategoriesInSuper, 30, super); + } + + Gentoo::OverviewCategoriesBySuper + Portage::getAllOverviewCategories(const Ice::Current &) + { + Gentoo::OverviewCategoriesBySuper rtn; + auto cats = fetchCache(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(sql::portage::getOverviewCategoriesInSuper, 30, super); + } + + Gentoo::PackagePtr + Portage::getPackage(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackage, 30, id); + } + + Gentoo::PackagePtr + Portage::findPackage(const std::string_view cat, const std::string_view pkg, const Ice::Current &) + { + return fetchCache(sql::portage::findPackage, 30, cat, pkg); + } + + Gentoo::Packages + Portage::getAllPackages(const Ice::Current &) + { + return fetchCache(sql::portage::getAllPackages, 30); + } + + Gentoo::Packages + Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackagesInCategory, 30, id); + } + + Gentoo::SearchResultPackages + Portage::getPackagesSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache(sql::portage::getPackagesSearch, 30, query, query); + } + + Gentoo::Ebuilds + Portage::getPackageVersions(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageVersions, 30, id); + } + + Gentoo::EbuildDetails + Portage::getPackageVersionDetails(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageVersionDetails, 30, id); + } + + Gentoo::ChangeLog + Portage::getPackageChangeLog(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageChangeLog, 30, id); + } + + Gentoo::Ebuilds + Portage::getRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache(sql::portage::getRecentAdditions, 30, syncDays); + } + + Gentoo::Packages + Portage::getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache(sql::portage::getPackagesWithRecentAdditions, 30, syncDays); + } + + Gentoo::Packages + Portage::getTopTrackedPackages(Ice::Int n, const Ice::Current &) + { + return fetchCache(sql::portage::getTopTrackedPackages, 30, n); + } + + Gentoo::Packages + Portage::getUserTrackedPackages(Ice::Int userid, const Ice::Current &) + { + return fetchCache(sql::portage::getUserTrackedPackages, 30, userid); + } + + Gentoo::Ebuilds + Portage::getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) + { + return fetchCache(sql::portage::getUserTrackedRecentVersions, 30, userid, limit); + } + + Gentoo::StringList + Portage::getPackageUrls(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageUrls, 30, id); + } + + Gentoo::Ebuilds + Portage::getEbuildsByFilter(const std::string_view filter, const Ice::Current &) + { + return fetchCache(sql::portage::getEbuildsByFilter, 30, filter); + } + + Gentoo::Categories + Portage::getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) + { + return fetchCache(sql::portage::getCategoriesWithRecentAdditions, 30, syncDays); + } + + Gentoo::PackageDependencyPackages + Portage::getPackageDependencies(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageDependencies, 30, id); + } + + Gentoo::PackageDependencyPackages + Portage::getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageRuntimeDependencies, 30, id); + } + + Gentoo::PackageDependencyPackages + Portage::getPackagesDepending(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackagesDepending, 30, id); + } + + Gentoo::PackageMasks + Portage::getPackageMasks(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageMasks, 30, id); + } + + Gentoo::Uses + Portage::getPackageUses(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageUses, 30, id); + } + + Gentoo::UsePtr + Portage::getUse(const std::string_view use, const Ice::Current &) + { + return fetchCache(sql::portage::getUse, 30, use, use); + } + + Gentoo::Uses + Portage::getGlobalUses(const Ice::Current &) + { + return fetchCache(sql::portage::getGlobalUses, 30); + } + + Gentoo::Uses + Portage::getGroupUses(const std::string_view group, const Ice::Current &) + { + return fetchCache(sql::portage::getGroupUses, 30, group); + } + + Gentoo::StringList + Portage::getUseGroups(const Ice::Current &) + { + return fetchCache(sql::portage::getUseGroups, 30); + } + + Gentoo::Uses + Portage::getUseUsage(const std::string_view use, const Ice::Current &) + { + return fetchCache(sql::portage::getUseUsage, 30, use, use, use, use); + } + + Gentoo::Packages + Portage::getUsePackages(const std::string_view use, const Ice::Current &) + { + return fetchCache(sql::portage::getUsePackages, 30, use, use); + } + + Gentoo::Uses + Portage::getUsesSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache(sql::portage::getUsesSearch, 30, query); + } + + Gentoo::BugPtr + Portage::getBug(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getBug, 30, id); + } + + Gentoo::Bugs + Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) + { + return fetchCache(sql::portage::getPackageBugs, 30, packageId); + } + + Gentoo::SearchResultBugs + Portage::getBugsSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache(sql::portage::getBugsSearch, 30, query, query); + } + + Gentoo::NewsItemPtr + Portage::getNewsItem(const std::string_view id, const Ice::Current &) + { + return fetchCache(sql::portage::getNewsItem, 30, id); + } + + Gentoo::News + Portage::getNewsSearch(const std::string_view query, const Ice::Current &) + { + return fetchCache(sql::portage::getNewsSearch, 30, query); + } + + Gentoo::News + Portage::getNewsRecent(Ice::Int items, const Ice::Current &) + { + return fetchCache(sql::portage::getNewsRecent, 30, items); + } + + Gentoo::Repository + Portage::getRepository(Ice::Int id, const Ice::Current &) + { + return fetchCache(sql::portage::getRepository, 30, id); + } + + Gentoo::Repositories + Portage::getRepositories(const Ice::Current &) + { + return fetchCache(sql::portage::getRepositories, 30); + } } - return rtn; -} - -Gentoo::OverviewCategories -Portage::getOverviewCategoriesInSuper(const std::string_view super, const Ice::Current &) -{ - return fetchCache(sql::portage::getOverviewCategoriesInSuper, 30, super); -} - -Gentoo::PackagePtr -Portage::getPackage(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackage, 30, id); -} - -Gentoo::PackagePtr -Portage::findPackage(const std::string_view cat, const std::string_view pkg, const Ice::Current &) -{ - return fetchCache(sql::portage::findPackage, 30, cat, pkg); } - -Gentoo::Packages -Portage::getAllPackages(const Ice::Current &) -{ - return fetchCache(sql::portage::getAllPackages, 30); -} - -Gentoo::Packages -Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackagesInCategory, 30, id); -} - -Gentoo::SearchResultPackages -Portage::getPackagesSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackagesSearch, 30, query, query); -} - -Gentoo::Ebuilds -Portage::getPackageVersions(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageVersions, 30, id); -} - -Gentoo::EbuildDetails -Portage::getPackageVersionDetails(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageVersionDetails, 30, id); -} - -Gentoo::ChangeLog -Portage::getPackageChangeLog(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageChangeLog, 30, id); -} - -Gentoo::Ebuilds -Portage::getRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache(sql::portage::getRecentAdditions, 30, syncDays); -} - -Gentoo::Packages -Portage::getPackagesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackagesWithRecentAdditions, 30, syncDays); -} - -Gentoo::Packages -Portage::getTopTrackedPackages(Ice::Int n, const Ice::Current &) -{ - return fetchCache(sql::portage::getTopTrackedPackages, 30, n); -} - -Gentoo::Packages -Portage::getUserTrackedPackages(Ice::Int userid, const Ice::Current &) -{ - return fetchCache(sql::portage::getUserTrackedPackages, 30, userid); -} - -Gentoo::Ebuilds -Portage::getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) -{ - return fetchCache(sql::portage::getUserTrackedRecentVersions, 30, userid, limit); -} - -Gentoo::StringList -Portage::getPackageUrls(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageUrls, 30, id); -} - -Gentoo::Ebuilds -Portage::getEbuildsByFilter(const std::string_view filter, const Ice::Current &) -{ - return fetchCache(sql::portage::getEbuildsByFilter, 30, filter); -} - -Gentoo::Categories -Portage::getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &) -{ - return fetchCache(sql::portage::getCategoriesWithRecentAdditions, 30, syncDays); -} - -Gentoo::PackageDependencyPackages -Portage::getPackageDependencies(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageDependencies, 30, id); -} - -Gentoo::PackageDependencyPackages -Portage::getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageRuntimeDependencies, 30, id); -} - -Gentoo::PackageDependencyPackages -Portage::getPackagesDepending(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackagesDepending, 30, id); -} - -Gentoo::PackageMasks -Portage::getPackageMasks(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageMasks, 30, id); -} - -Gentoo::Uses -Portage::getPackageUses(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageUses, 30, id); -} - -Gentoo::UsePtr -Portage::getUse(const std::string_view use, const Ice::Current &) -{ - return fetchCache(sql::portage::getUse, 30, use, use); -} - -Gentoo::Uses -Portage::getGlobalUses(const Ice::Current &) -{ - return fetchCache(sql::portage::getGlobalUses, 30); -} - -Gentoo::Uses -Portage::getGroupUses(const std::string_view group, const Ice::Current &) -{ - return fetchCache(sql::portage::getGroupUses, 30, group); -} - -Gentoo::StringList -Portage::getUseGroups(const Ice::Current &) -{ - return fetchCache(sql::portage::getUseGroups, 30); -} - -Gentoo::Uses -Portage::getUseUsage(const std::string_view use, const Ice::Current &) -{ - return fetchCache(sql::portage::getUseUsage, 30, use, use, use, use); -} - -Gentoo::Packages -Portage::getUsePackages(const std::string_view use, const Ice::Current &) -{ - return fetchCache(sql::portage::getUsePackages, 30, use, use); -} - -Gentoo::Uses -Portage::getUsesSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache(sql::portage::getUsesSearch, 30, query); -} - -Gentoo::BugPtr -Portage::getBug(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getBug, 30, id); -} - -Gentoo::Bugs -Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) -{ - return fetchCache(sql::portage::getPackageBugs, 30, packageId); -} - -Gentoo::SearchResultBugs -Portage::getBugsSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache(sql::portage::getBugsSearch, 30, query, query); -} - -Gentoo::NewsItemPtr -Portage::getNewsItem(const std::string_view id, const Ice::Current &) -{ - return fetchCache(sql::portage::getNewsItem, 30, id); -} - -Gentoo::News -Portage::getNewsSearch(const std::string_view query, const Ice::Current &) -{ - return fetchCache(sql::portage::getNewsSearch, 30, query); -} - -Gentoo::News -Portage::getNewsRecent(Ice::Int items, const Ice::Current &) -{ - return fetchCache(sql::portage::getNewsRecent, 30, items); -} - -Gentoo::Repository -Portage::getRepository(Ice::Int id, const Ice::Current &) -{ - return fetchCache(sql::portage::getRepository, 30, id); -} - -Gentoo::Repositories -Portage::getRepositories(const Ice::Current &) -{ - return fetchCache(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 #include #include -#include 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 #include +#include +#include #include +#include #include -#include #include +#include #include #include -#include -#include +#include #include +#include #include -#include #include -#include -#include -#include +#include +#include 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(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(sql::users::verify, username, verifyguid); -} - -Gentoo::UserPtr -Users::get(Ice::Int id, const Ice::Current &) -{ - return fetch(sql::users::get, id); -} - -Gentoo::NewUserPtr -Users::getNew(const std::string_view username, const std::string_view password, const Ice::Current &) -{ - return fetch(sql::users::getNew, username, password); -} - -Gentoo::UserPtr -Users::find(const std::string_view username, const Ice::Current &) -{ - return fetch(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>(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(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(sql::users::verify, username, verifyguid); + } + + Gentoo::UserPtr + Users::get(Ice::Int id, const Ice::Current &) + { + return fetch(sql::users::get, id); + } + + Gentoo::NewUserPtr + Users::getNew(const std::string_view username, const std::string_view password, const Ice::Current &) + { + return fetch(sql::users::getNew, username, password); + } + + Gentoo::UserPtr + Users::find(const std::string_view username, const Ice::Current &) + { + return fetch(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>(sql::users::getNew, username, password); + if (existing && *existing) { + return *existing; + } + return fetch(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(); + auto mailServer = IceTray::Cube::get(); + + 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(sql::users::tracked, 10, userId); + } } - return fetch(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(); - auto mailServer = IceTray::Cube::get(); - - 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(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 #include #include -#include 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 +#include #include -#include +#include #include -#include +#include namespace Gentoo { namespace Utils { @@ -22,7 +22,8 @@ namespace Gentoo { } std::pair - namedTemp(DB::Connection * db, const std::string & tempTable, const std::map & cols) + namedTemp(DB::Connection * db, const std::string & tempTable, + const std::map & cols) { std::set keys; std::set 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 & c) { - return dbc->modify( - "INSERT INTO " + t + - "(" + boost::algorithm::join(c, ", ") + - ") VALUES(" + boost::algorithm::join(std::vector(c.size(), "?"), ", ") + ")"); + return dbc->modify("INSERT INTO " + t + "(" + boost::algorithm::join(c, ", ") + ") VALUES(" + + boost::algorithm::join(std::vector(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 -#include -#include #include #include +#include +#include +#include namespace Gentoo { namespace Utils { namespace Database { std::string emptyClone(DB::Connection *, const std::string &); - std::pair namedTemp(DB::Connection *, const std::string &, const std::map & cols); + std::pair namedTemp( + DB::Connection *, const std::string &, const std::map & 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 &); + DB::ModifyCommandPtr tablePatchInserter( + DB::Connection *, const std::string &, const std::set &); } } } #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 -#include -#include -#include #include #include +#include +#include +#include namespace Gentoo { namespace Utils { class EbuildCacheParser : public AdHoc::FileUtils::MemMap { - public: - typedef std::map KVs; + public: + typedef std::map KVs; - EbuildCacheParser(const std::filesystem::path & p); + EbuildCacheParser(const std::filesystem::path & p); - std::optional get(const std::string & key) const; - std::optional getRange(const std::string & key) const; + std::optional get(const std::string & key) const; + std::optional 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 - EntityWhereFilter::EntityWhereFilter(const std::string & en) : - entityColName(en) - { - } + template EntityWhereFilter::EntityWhereFilter(const std::string & en) : entityColName(en) { } template - EntityWhereFilter::EntityWhereFilter(const std::string & en, const T & e) : - entityColName(en) + EntityWhereFilter::EntityWhereFilter(const std::string & en, const T & e) : entityColName(en) { entityIds.insert(e); } template EntityWhereFilter::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; } } - 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 #include +#include namespace Gentoo { namespace Utils { - template - class EntityWhereFilter : public DB::SqlWriter { - public: - typedef std::set EntityIds; + template class EntityWhereFilter : public DB::SqlWriter { + public: + typedef std::set 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 -#include #include +#include #include +#include 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(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( + 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 #include +#include #include namespace Gentoo { @@ -10,30 +10,29 @@ namespace Gentoo { namespace Git { void throwError(void * const func, int err); - template + template 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 - using GitTPtr = std::unique_ptr; + template using GitTPtr = std::unique_ptr; - template + template GitTPtr - 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, release); } - template + template 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; - 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 #include "dbUtils.h" +#include namespace Gentoo { namespace Utils { - SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional & p) : + SplitEbuildProps::SplitEbuildProps( + const std::string & ce, int e, const std::string & cp, const std::optional & 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 #include #include +#include namespace Gentoo { namespace Utils { class SplitEbuildProps : public DB::SqlWriter { - public: - SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional & p); + public: + SplitEbuildProps( + const std::string & ce, int e, const std::string & cp, const std::optional & 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 props; + const int entityId; + const std::string colEntityName, colPropName; + const std::optional 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 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 #include +#include #include namespace Gentoo { namespace Utils { class XmlDoc : public xmlpp::DomParser { - public: - XmlDoc(const std::filesystem::path &); + public: + XmlDoc(const std::filesystem::path &); - std::optional getXPathValue(const Glib::ustring &); + std::optional 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 -#include #include -#include -#include +#include +#include #include #include +#include +#include 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(Headers {}, "alternative", Parts { - getText(result.get()), getHtml(result.get()) - }); + mail->content = std::make_shared( + 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(Headers {}, "related", Parts { - std::make_shared(Headers {}, "text/html", strm.str()), - std::make_shared(Headers { - { "Content-Id", "" }, - }, "text/css", css), - }); + return std::make_shared(Headers {}, "related", + Parts { + std::make_shared(Headers {}, "text/html", strm.str()), + std::make_shared( + Headers { + {"Content-Id", ""}, + }, + "text/css", css), + }); } - IceTray::Mime::BasicPartPtr XsltStreamSerializer::getText(xmlDoc * result) + IceTray::Mime::BasicPartPtr + XsltStreamSerializer::getText(xmlDoc * result) { std::stringstream strm; std::vector callLynx; @@ -90,4 +93,3 @@ namespace Gentoo { return std::make_shared(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 -#include #include #include +#include +#include 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 -#include -#include #include -#include #include +#include +#include +#include Service::Service() : - DB::PluginMock("GentooBrowseAPI", { - rootDir.parent_path() / "db" / "schema.sql", - rootDir / "data.sql" }, + DB::PluginMock("GentooBrowseAPI", {rootDir.parent_path() / "db" / "schema.sql", rootDir / "data.sql"}, "user=postgres dbname=postgres") { IceTray::DryIce::replace(); } 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("GentooBrowseAPI", { - rootDir.parent_path() / "db" / "schema.sql" }, - "user=postgres dbname=postgres") + "--GentooBrowseAPI.BugRoot=file://" + (rootDir / "fixtures" / "bugs").string()}), + DB::PluginMock( + "GentooBrowseAPI", {rootDir.parent_path() / "db" / "schema.sql"}, "user=postgres dbname=postgres") { IceTray::DryIce::replace(); } @@ -31,15 +26,13 @@ Maintenance::Maintenance() : Mail::Mail() : IceTray::DryIce({ "--GentooBrowseAPI.MailServer=smtp.random.lan:25", - }) + }) { } TestClient::TestClient() : - m(IceTray::Cube::get()), - p(IceTray::Cube::get()), - n(IceTray::Cube::get()), - ms(IceTray::Cube::get()), + m(IceTray::Cube::get()), p(IceTray::Cube::get()), + n(IceTray::Cube::get()), ms(IceTray::Cube::get()), u(IceTray::Cube::get()) { BOOST_REQUIRE(m); @@ -68,13 +61,13 @@ TestClient::humanReadableParts(IceTray::Mail::EmailPtr e) auto htmlPart = std::dynamic_pointer_cast(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: \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 -#include +#include #include -#include -#include #include +#include #include +#include +#include #include -#include -#include +#include +#include class DLL_PUBLIC Service : public IceTray::DryIce, DB::PluginMock { - public: - Service(); +public: + Service(); }; class DLL_PUBLIC Maintenance : public IceTray::DryIce, DB::PluginMock { - 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 - 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 humanReadableParts(IceTray::Mail::EmailPtr e); }; -#define SQL_REQUIRE_EQUAL(sql, type, expected) BOOST_TEST_CONTEXT(sql) { sqlRequireEqual(db, sql, expected); } +#define SQL_REQUIRE_EQUAL(sql, type, expected) \ + BOOST_TEST_CONTEXT(sql) { \ + sqlRequireEqual(db, sql, expected); \ + } template -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([expected,&assertedRows](const auto & n) { + db->select(sql)->forEachRow([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 -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 #include "mockDefs.h" -#include #include -#include -#include +#include #include +#include #include -#include #include +#include +#include -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 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 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(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 -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 -#include -#include +#include +#include #include +#include +#include #include -#include -#include class MaskTester : public Portage::Utils::Masks { - protected: - void consume() const override - { - if (email && person) { - masks.push_back(std::make_shared(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(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 -#include -#include #include +#include +#include -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 #include +#include #include "mockDefs.h" #include #include +#include +#include #include #include -#include -#include using namespace std::string_literals; using QPTD = std::tuple; -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(1, "testuser", "Test User", "dan@randomdan.homeip.net", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); + Gentoo::NewUserPtr u = std::make_shared( + 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(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None, "some-guid"); + Gentoo::NewUserPtr u = std::make_shared( + 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(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None); - Gentoo::NewsContent nc { - { - std::make_shared(1, "app-test", "Test cat1"s), - std::make_shared(2, "sys-test", "Test cat2"s), - std::make_shared(3, "no-show", "Unused cat"s) - }, - { - std::make_shared(1, 1, "app1", "first-seen", "Test app desc one", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared(2, 1, "app2", "first-seen", "Test app desc two", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared(3, 2, "app3", "first-seen", "Test app desc three", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), - std::make_shared(4, 2, "app4", "first-seen", "Test app no-show", "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None) - }, - { - std::make_shared(1, 1, 1, "1.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(2, 1, 1, "1.1a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(3, 1, 1, "1.2a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(4, 2, 1, "2.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(5, 3, 1, "3.0a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(6, 2, 1, "2.1a", "slot", "first-seen", "last-mod", IceUtil::None), - std::make_shared(7, 3, 1, "3.1a", "slot", "first-seen", "last-mod", IceUtil::None) - } - }; + Gentoo::UserPtr u = std::make_shared( + 1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None); + Gentoo::NewsContent nc {{std::make_shared(1, "app-test", "Test cat1"s), + std::make_shared(2, "sys-test", "Test cat2"s), + std::make_shared(3, "no-show", "Unused cat"s)}, + {std::make_shared(1, 1, "app1", "first-seen", "Test app desc one", "Test summary 1"s, + IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared(2, 1, "app2", "first-seen", "Test app desc two", + "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared(3, 2, "app3", "first-seen", "Test app desc three", + "Test summary 1"s, IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None), + std::make_shared(4, 2, "app4", "first-seen", "Test app no-show", "Test summary 1"s, + IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None)}, + {std::make_shared(1, 1, 1, "1.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared(2, 1, 1, "1.1a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared(3, 1, 1, "1.2a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared(4, 2, 1, "2.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared(5, 3, 1, "3.0a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared(6, 2, 1, "2.1a", "slot", "first-seen", "last-mod", IceUtil::None), + std::make_shared( + 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 -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(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 #include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include 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 ostream & operator<<(ostream & s, const Ice::optional & 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 ", *cl.front()->body); + BOOST_REQUIRE_EQUAL( + "Package-Manager: portage-2.2.28\nSigned-off-by: Alexis Ballier ", *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 #include +#include #include +#include #include #include -#include void testDependRange(const std::optional & r) @@ -16,18 +16,17 @@ testDependRange(const std::optional & 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 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()); @@ -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 -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(); 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 -#include +#include #include #include #include -#include +#include 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 #include #include +#include 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> 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; } - -- cgit v1.2.3