From 8f8c83cba2d58f0b465dc0a105ede7ebc36e64ef Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Apr 2016 00:18:15 +0100 Subject: Ingest package declarations from manifests --- .../maintenance/packageManifestProcessor.cpp | 33 ++++++++++++++++++++++ .../service/maintenance/packageManifestProcessor.h | 22 +++++++++++++++ gentoobrowse-api/service/maintenanceimpl.cpp | 2 ++ .../service/sql/maintenance/packageDelete.sql | 4 +++ .../service/sql/maintenance/packageInsert.sql | 4 +++ gentoobrowse-api/unittests/testMaintenance.cpp | 14 +++++++++ 6 files changed, 79 insertions(+) create mode 100644 gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp create mode 100644 gentoobrowse-api/service/maintenance/packageManifestProcessor.h create mode 100644 gentoobrowse-api/service/sql/maintenance/packageDelete.sql create mode 100644 gentoobrowse-api/service/sql/maintenance/packageInsert.sql diff --git a/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp new file mode 100644 index 0000000..8d6147c --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp @@ -0,0 +1,33 @@ +#include "packageManifestProcessor.h" +#include +#include "fileUtils.h" +#include +#include + +using namespace Gentoo::Utils::File; + +namespace Gentoo { + namespace Service { + const int PackageManifestProcessor::FILETYPEID = 8; + + void + PackageManifestProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path &) const + { + auto m = dbc->modify(sql::maintenance::packageInsert::sql); + m->bindParamS(0, (fn / 2).string()); + m->bindParamS(1, fn.parent_path().string()); + m->bindParamS(2, (fn / 1).string()); + m->execute(); + } + + void + PackageManifestProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const + { + auto m = dbc->modify(sql::maintenance::packageDelete::sql); + m->bindParamS(0, (fn / 2).string()); + m->bindParamS(1, (fn / 1).string()); + m->execute(); + } + } +} + diff --git a/gentoobrowse-api/service/maintenance/packageManifestProcessor.h b/gentoobrowse-api/service/maintenance/packageManifestProcessor.h new file mode 100644 index 0000000..f7347b2 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageManifestProcessor.h @@ -0,0 +1,22 @@ +#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMANIFESTPROC_H +#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMANIFESTPROC_H + +#include "../maintenanceimpl.h" +#include +#include +#include + +namespace Gentoo { + namespace Service { + class PackageManifestProcessor : public Maintenance::FileProcessor { + public: + static const int FILETYPEID; + + void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; + }; + } +} + +#endif + diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index 9b8b550..d8b85ef 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -7,6 +7,7 @@ #include #include #include "maintenance/categoryMetaProcessor.h" +#include "maintenance/packageManifestProcessor.h" /* 1 package metadata {"(1,metadata)","(2,md5-cache)"} @@ -47,6 +48,7 @@ namespace Gentoo { IceTray::AbstractDatabaseClient(d) { fps[CategoryMetaProcessor::FILETYPEID] = new CategoryMetaProcessor(); + fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); } Maintenance::~Maintenance() diff --git a/gentoobrowse-api/service/sql/maintenance/packageDelete.sql b/gentoobrowse-api/service/sql/maintenance/packageDelete.sql new file mode 100644 index 0000000..5a2a0f1 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageDelete.sql @@ -0,0 +1,4 @@ +DELETE FROM gentoobrowse.packages p +USING gentoobrowse.categories c +WHERE p.name = ? +AND c.name = ? diff --git a/gentoobrowse-api/service/sql/maintenance/packageInsert.sql b/gentoobrowse-api/service/sql/maintenance/packageInsert.sql new file mode 100644 index 0000000..223cdbe --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageInsert.sql @@ -0,0 +1,4 @@ +INSERT INTO gentoobrowse.packages(categoryid, name, description) +SELECT c.categoryid, ?, ? +FROM gentoobrowse.categories c +WHERE c.name = ? diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index b8bb5d4..2b3a4ba 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -58,12 +58,26 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 2084); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 5); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories WHERE name = 'dev-vcs'", int64_t, 1); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 478); + db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'"); sd.extract("756569aa764177340726dd3d40b41d89b11b20c7", "gentoo"); m->refreshPackageTree(); sd.clean(); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 2034); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 5); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories WHERE name = 'dev-vcs'", int64_t, 1); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 480); + db->execute("COPY gentoobrowse.categories TO '/tmp/categories2.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages2.tsv'"); + m->refreshPackageTree(); + + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 0); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 0); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 0); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3