summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp2
-rw-r--r--gentoobrowse-api/service/maintenance/useLocalProcessor.cpp63
-rw-r--r--gentoobrowse-api/service/maintenance/useLocalProcessor.h23
-rw-r--r--gentoobrowse-api/service/maintenanceimpl.cpp4
-rw-r--r--gentoobrowse-api/service/sql/maintenance/rawUseLocalDesc.sql7
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.cpp31
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.h3
-rw-r--r--gentoobrowse-api/unittests/testMaintenance.cpp11
8 files changed, 135 insertions, 9 deletions
diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
index caa75c0..a860112 100644
--- a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
@@ -29,7 +29,7 @@ namespace Gentoo {
p.cols = { "use", "description" };
Utils::MemMap u(path);
- Glib::ustring d(reinterpret_cast<const char *>(u.data), u.getStat().st_size);
+ Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size));
Glib::MatchInfo matches;
auto i = Utils::Database::tablePatchInserter(dbc, p);
for (useDesc->match(d, matches); matches.get_match_count() == 3; matches.next()) {
diff --git a/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp
new file mode 100644
index 0000000..4ce5d55
--- /dev/null
+++ b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp
@@ -0,0 +1,63 @@
+#include "useLocalProcessor.h"
+#include <modifycommand.h>
+#include <sqlWriter.h>
+#include <tablepatch.h>
+#include "utils/fileUtils.h"
+#include "utils/dbUtils.h"
+#include <glibmm/regex.h>
+#include "sql/maintenance/rawUseLocalDesc.sql.h"
+
+using namespace Gentoo::Utils::File;
+
+static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^/]*)/([^:]+):([^ ]+)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE);
+
+namespace Gentoo {
+ namespace Service {
+ const int UseLocalProcessor::FILETYPEID = 6;
+
+ void
+ UseLocalProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const
+ {
+ modified(dbc, fn, path);
+ }
+
+ void
+ UseLocalProcessor::modified(DB::Connection * dbc, const boost::filesystem::path &, const boost::filesystem::path & path) const
+ {
+ DB::TablePatch p;
+ auto tempTable = Utils::Database::namedTemp(dbc, "rawuselocaldesc", {
+ { "category", "text" },
+ { "package", "text" },
+ { "use", "text" },
+ { "description", "text" }
+ });
+ p.dest = "gentoobrowse.use_local";
+ DB::StaticSqlWriter srcExpr(sql::maintenance::rawUseLocalDesc::sql);
+ p.srcExpr = &srcExpr;
+ p.pk = { "packageId", "use" };
+ p.cols = { "packageId", "use", "description" };
+
+ Utils::MemMap u(path);
+ Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size));
+ Glib::MatchInfo matches;
+ auto i = tempTable.second;
+ for (useDesc->match(d, matches); matches.get_match_count() == 5; matches.next()) {
+ i->bindParamS(0, matches.fetch(1));
+ i->bindParamS(1, matches.fetch(4));
+ i->bindParamS(2, matches.fetch(2));
+ i->bindParamS(3, matches.fetch(3));
+ i->execute();
+ }
+ dbc->patchTable(&p);
+
+ Utils::Database::drop(dbc, tempTable.first);
+ }
+
+ void
+ UseLocalProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path &) const
+ {
+ dbc->modify("DELETE FROM gentoobrowse.use_local")->execute();
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/maintenance/useLocalProcessor.h b/gentoobrowse-api/service/maintenance/useLocalProcessor.h
new file mode 100644
index 0000000..ab0663d
--- /dev/null
+++ b/gentoobrowse-api/service/maintenance/useLocalProcessor.h
@@ -0,0 +1,23 @@
+#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_USELOCALPROC_H
+#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_USELOCALPROC_H
+
+#include "../maintenanceimpl.h"
+#include <connection.h>
+#include <modifycommand.h>
+#include <boost/filesystem/path.hpp>
+
+namespace Gentoo {
+ namespace Service {
+ class UseLocalProcessor : 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 modified(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 7f7bb65..d08f961 100644
--- a/gentoobrowse-api/service/maintenanceimpl.cpp
+++ b/gentoobrowse-api/service/maintenanceimpl.cpp
@@ -11,17 +11,18 @@
#include "maintenance/packageMetaProcessor.h"
#include "maintenance/ebuildMetaProcessor.h"
#include "maintenance/useGlobalProcessor.h"
+#include "maintenance/useLocalProcessor.h"
/*
10 category metadata.xml {"(2,metadata.xml)"}
4 package metadata.xml {"(3,metadata.xml)"}
1 ebuild metadata {"(1,metadata)","(2,md5-cache)"}
5 use_global {"(1,profiles)","(2,use.desc)"}
+6 use_local {"(1,profiles)","(2,use.local.desc)"}
8 package manifests {"(3,Manifest)"}
2 changelog {"(3,ChangeLog)"}
3 masks {"(1,profiles)","(2,package.mask)"}
-6 use_local {"(1,profiles)","(2,use.local.desc)"}
7 licenses {"(1,licenses)"}
9 use_grouped {"(1,profiles)","(2,desc)","(3,%.desc)"}
11 news {"(1,metadata)","(2,news)","(4,%.txt)"}
@@ -56,6 +57,7 @@ namespace Gentoo {
fps[PackageMetaProcessor::FILETYPEID] = new PackageMetaProcessor();
fps[EbuildMetaProcessor::FILETYPEID] = new EbuildMetaProcessor();
fps[UseGlobalProcessor::FILETYPEID] = new UseGlobalProcessor();
+ fps[UseLocalProcessor::FILETYPEID] = new UseLocalProcessor();
}
Maintenance::~Maintenance()
diff --git a/gentoobrowse-api/service/sql/maintenance/rawUseLocalDesc.sql b/gentoobrowse-api/service/sql/maintenance/rawUseLocalDesc.sql
new file mode 100644
index 0000000..dedfbc8
--- /dev/null
+++ b/gentoobrowse-api/service/sql/maintenance/rawUseLocalDesc.sql
@@ -0,0 +1,7 @@
+(
+ SELECT p.packageId, d.use, d.description
+ FROM gentoobrowse.categories c, gentoobrowse.packages p, rawuselocaldesc d
+ WHERE c.categoryId = p.categoryId
+ AND c.name = d.category
+ AND p.name = d.package
+)
diff --git a/gentoobrowse-api/service/utils/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp
index 4ec0f54..c368c7a 100644
--- a/gentoobrowse-api/service/utils/dbUtils.cpp
+++ b/gentoobrowse-api/service/utils/dbUtils.cpp
@@ -32,6 +32,26 @@ namespace Gentoo {
return tempTable;
}
+ std::pair<std::string, DB::ModifyCommandPtr>
+ customTemp(DB::Connection * db, const std::map<std::string, const std::string> & cols)
+ {
+ return namedTemp(db, "tmp_" + boost::lexical_cast<std::string>(db), cols);
+ }
+
+ std::pair<std::string, DB::ModifyCommandPtr>
+ namedTemp(DB::Connection * db, const std::string & tempTable, const std::map<std::string, const std::string> & cols)
+ {
+ std::set<std::string> keys;
+ std::set<std::string> defs;
+ for (auto c : cols) {
+ 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) };
+ }
+
void
drop(DB::Connection * db, const std::string & table)
{
@@ -41,10 +61,15 @@ namespace Gentoo {
DB::ModifyCommandPtr
tablePatchInserter(DB::Connection * dbc, const DB::TablePatch & p)
{
+ return tablePatchInserter(dbc, p.src, p.cols);
+ }
+ DB::ModifyCommandPtr
+ tablePatchInserter(DB::Connection * dbc, const std::string & t, const std::set<std::string> & c)
+ {
return dbc->modify(
- "INSERT INTO " + p.src +
- "(" + boost::algorithm::join(p.cols, ", ") +
- ") VALUES(" + boost::algorithm::join(std::vector<std::string>(p.cols.size(), "?"), ", ") + ")");
+ "INSERT INTO " + t +
+ "(" + boost::algorithm::join(c, ", ") +
+ ") VALUES(" + boost::algorithm::join(std::vector<std::string>(c.size(), "?"), ", ") + ")");
}
}
}
diff --git a/gentoobrowse-api/service/utils/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h
index 57554e3..95ae868 100644
--- a/gentoobrowse-api/service/utils/dbUtils.h
+++ b/gentoobrowse-api/service/utils/dbUtils.h
@@ -11,8 +11,11 @@ namespace Gentoo {
bool bindOptionalsS(DB::Command * db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs);
std::string emptyClone(DB::Connection *, const std::string &);
+ std::pair<std::string, DB::ModifyCommandPtr> customTemp(DB::Connection *, const std::map<std::string, const std::string> & cols);
+ std::pair<std::string, DB::ModifyCommandPtr> namedTemp(DB::Connection *, const std::string &, const std::map<std::string, const std::string> & cols);
void drop(DB::Connection *, const std::string &);
DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const DB::TablePatch &);
+ DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const std::string &, const std::set<std::string> &);
}
}
}
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index abaf611..d5bf738 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -45,7 +45,7 @@ BOOST_FIXTURE_TEST_SUITE(tp, TestClient)
void
doRefreshPackageTree(SampleData & sd, DB::ConnectionPtr db, const std::string & archive, const std::string & dir,
Gentoo::MaintenancePrx m, int64_t files, int64_t cats, int64_t devvcs, int64_t pkgs, int64_t ebs, int64_t ebus,
- int64_t ebas, int64_t pus, int64_t ug)
+ int64_t ebas, int64_t pus, int64_t ug, int64_t ul)
{
if (!archive.empty()) {
sd.extract(archive, dir);
@@ -62,6 +62,7 @@ doRefreshPackageTree(SampleData & sd, DB::ConnectionPtr db, const std::string &
SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_archs", int64_t, ebas);
SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.package_urls", int64_t, pus);
SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_global", int64_t, ug);
+ SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_local", int64_t, ul);
}
BOOST_AUTO_TEST_CASE( refreshPackageTree )
@@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
insRepo->execute();
doRefreshPackageTree(sd, db, "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", "gentoo",
- m, 2084, 5, 1, 482, 981, 3626, 4593, 501, 393);
+ m, 2084, 5, 1, 482, 981, 3626, 4593, 501, 393, 238);
db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'");
db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'");
@@ -83,9 +84,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs1.tsv'");
db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls1.tsv'");
db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global1.tsv'");
+ db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local1.tsv'");
doRefreshPackageTree(sd, db, "756569aa764177340726dd3d40b41d89b11b20c7", "gentoo",
- m, 2087, 5, 1, 484, 982, 3638, 4599, 503, 393);
+ m, 2087, 5, 1, 484, 982, 3638, 4599, 503, 393, 238);
db->execute("COPY gentoobrowse.categories TO '/tmp/categories2.tsv'");
db->execute("COPY gentoobrowse.packages TO '/tmp/packages2.tsv'");
@@ -94,9 +96,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs2.tsv'");
db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls2.tsv'");
db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global2.tsv'");
+ db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local2.tsv'");
doRefreshPackageTree(sd, db, "", "gentoo",
- m, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ m, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
m->refreshPackageTree();
}