From 9b824e6f34a15a0dbe382b65c94a380afa4d4d1f Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
Date: Fri, 27 May 2016 21:25:06 +0100
Subject: Move maintenanceimpl.cpp so parts can be separate

---
 .../service/maintenancePackageTree.cpp             | 205 +++++++++++++++++++++
 gentoobrowse-api/service/maintenanceimpl.cpp       | 205 ---------------------
 2 files changed, 205 insertions(+), 205 deletions(-)
 create mode 100644 gentoobrowse-api/service/maintenancePackageTree.cpp
 delete mode 100644 gentoobrowse-api/service/maintenanceimpl.cpp

diff --git a/gentoobrowse-api/service/maintenancePackageTree.cpp b/gentoobrowse-api/service/maintenancePackageTree.cpp
new file mode 100644
index 0000000..8347d07
--- /dev/null
+++ b/gentoobrowse-api/service/maintenancePackageTree.cpp
@@ -0,0 +1,205 @@
+#include "maintenanceimpl.h"
+#include <selectcommandUtil.impl.h>
+#include <tablepatch.h>
+#include <sqlWriter.h>
+#include <buffer.h>
+#include <scopeExit.h>
+#include <boost/filesystem/operations.hpp>
+#include <sql/maintenance/fileListCreateRaw.sql.h>
+#include <sql/maintenance/fileListCreate.sql.h>
+#include <sql/maintenance/fileListCreatePk.sql.h>
+#include "maintenance/categoryMetaProcessor.h"
+#include "maintenance/packageManifestProcessor.h"
+#include "maintenance/packageMetaProcessor.h"
+#include "maintenance/ebuildMetaProcessor.h"
+#include "maintenance/useGlobalProcessor.h"
+#include "maintenance/useLocalProcessor.h"
+#include "maintenance/useGroupProcessor.h"
+#include "maintenance/masksProcessor.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)"}
+9	use_grouped	{"(1,profiles)","(2,desc)","(3,%.desc)"}
+3	masks	{"(1,profiles)","(2,package.mask)"}
+
+8	package manifests	{"(3,Manifest)"}
+2	changelog	{"(3,ChangeLog)"}
+7	licenses	{"(1,licenses)"}
+11	news	{"(1,metadata)","(2,news)","(4,%.txt)"}
+*/
+
+namespace Gentoo {
+	namespace Service {
+		Maintenance::FileProcessor::~FileProcessor()
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::prepare(DB::Connection *)
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::apply(DB::Connection *)
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::tidy(DB::Connection *)
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::created(DB::Connection *, const boost::filesystem::path &, const boost::filesystem::path &)
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::modified(DB::Connection *, const boost::filesystem::path &, const boost::filesystem::path &)
+		{
+		}
+
+		void
+		Maintenance::FileProcessor::deleted(DB::Connection *, const boost::filesystem::path &)
+		{
+		}
+
+		template<typename T>
+		Maintenance::FileProcessorPtr
+		Maintenance::createFileProessor()
+		{
+			return FileProcessorPtr(new T());
+		}
+
+		Maintenance::Maintenance(IceTray::DatabasePoolPtr d) :
+			IceTray::AbstractDatabaseClient(d)
+		{
+			fpfs[CategoryMetaProcessor::FILETYPEID] = &createFileProessor<CategoryMetaProcessor>;
+			fpfs[PackageManifestProcessor::FILETYPEID] = &createFileProessor<PackageManifestProcessor>;
+			fpfs[PackageMetaProcessor::FILETYPEID] = &createFileProessor<PackageMetaProcessor>;
+			fpfs[EbuildMetaProcessor::FILETYPEID] = &createFileProessor<EbuildMetaProcessor>;
+			fpfs[UseGlobalProcessor::FILETYPEID] = &createFileProessor<UseGlobalProcessor>;
+			fpfs[UseLocalProcessor::FILETYPEID] = &createFileProessor<UseLocalProcessor>;
+			fpfs[UseGroupProcessor::FILETYPEID] = &createFileProessor<UseGroupProcessor>;
+			fpfs[MasksProcessor::FILETYPEID] = &createFileProessor<MasksProcessor>;
+		}
+
+		Maintenance::~Maintenance()
+		{
+		}
+
+		void
+		Maintenance::fileDeleted(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
+		{
+			// b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid
+			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) {
+					this->fileHandle(ft, fps, boost::bind(&FileProcessor::deleted, _1, dbc, fn));
+				});
+		}
+
+		void
+		Maintenance::fileChanged(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
+		{
+			// a.filename, a.filesize old_filesize, a.filetypeid old_filetypeid, a.moddate old_moddate, a.pathparts old_pathparts,a.repoid old_repoid,  b.filesize new_filesize, b.filetypeid new_filetypeid, b.moddate new_moddate, b.pathparts new_pathparts, b.repoid new_repoid
+			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto, auto, auto, auto, auto, auto) {
+					this->fileHandle(ft, fps, boost::bind(&FileProcessor::modified, _1, dbc, fn, tmp / fn));
+				});
+		}
+
+		void
+		Maintenance::fileCreated(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
+		{
+			// b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid
+			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) {
+					this->fileHandle(ft, fps, boost::bind(&FileProcessor::created, _1, dbc, fn, tmp / fn));
+				});
+		}
+
+		void
+		Maintenance::fileHandle(int64_t ft, const FileProcessors * fps, const FileHandleFunc & f) const
+		{
+			auto i = fps->find(ft);
+			if (i != fps->end()) {
+				f(i->second);
+			}
+		}
+
+		void
+		Maintenance::createTempFileList(DB::Connection * dbc, const boost::filesystem::path & tmp)
+		{
+			boost::filesystem::remove_all(tmp);
+			boost::filesystem::create_directories(tmp);
+			dbc->select("SELECT name, path FROM gentoobrowse.repos")->forEachRow<std::string, std::string>([&tmp](auto n, auto p) {
+					boost::filesystem::create_symlink(p, tmp / n);
+				});
+			dbc->execute(sql::maintenance::fileListCreateRaw.getSql());
+			dbc->beginBulkUpload("filelistraw", "");
+			char buf[BUFSIZ];
+			for (boost::filesystem::recursive_directory_iterator d(tmp, boost::filesystem::symlink_option::recurse);
+					d != boost::filesystem::recursive_directory_iterator(); d++) {
+				if (boost::filesystem::is_regular_file(d->status())) {
+					auto len = snprintf(buf, BUFSIZ, "%s\t%ld\t%s\n",
+						d->path().lexically_relative(tmp).c_str(),
+						boost::filesystem::file_size(*d),
+						boost::posix_time::to_iso_extended_string(
+							boost::posix_time::from_time_t(boost::filesystem::last_write_time(*d))).c_str());
+					dbc->bulkUploadData(buf, len);
+				}
+			}
+			dbc->endBulkUpload(nullptr);
+		}
+
+		void
+		Maintenance::processChanges(DB::Connection * dbc, const boost::filesystem::path & tmp)
+		{
+			FileProcessors fps;
+			for (const auto & fpf : fpfs) {
+				fps[fpf.first] = fpf.second();
+			}
+			for (const auto & fp : fps) {
+				fp.second->prepare(dbc);
+			}
+			dbc->execute(sql::maintenance::fileListCreate.getSql());
+			dbc->execute(sql::maintenance::fileListCreatePk.getSql());
+			DB::TablePatch tp;
+			tp.src = "filelist";
+			tp.dest = "gentoobrowse.files";
+			tp.pk = {"filename"};
+			tp.cols = {"repoid", "filename", "filetypeid", "pathparts", "filesize", "moddate"};
+			tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, &fps, tmp, _1);
+			tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, &fps, tmp, _1);
+			tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, &fps, tmp, _1);
+			DB::StaticSqlWriter obpo("processOrder NULLS LAST");
+			tp.order = &obpo;
+			dbc->patchTable(&tp);
+			for (const auto & fp : fps) {
+				fp.second->apply(dbc);
+			}
+			dbc->execute("DROP TABLE filelist");
+			for (const auto & fp : fps) {
+				fp.second->tidy(dbc);
+			}
+		}
+
+		void
+		Maintenance::refreshPackageTree(const Ice::Current &)
+		{
+			auto tmp = boost::filesystem::temp_directory_path() / "import";
+			AdHoc::ScopeExit tidyTmp([&tmp]{
+					boost::system::error_code ec;
+					boost::filesystem::remove_all(tmp, ec);
+				});
+			auto dbc = db->get();
+			dbc->execute("SET search_path = gentoobrowse, pg_catalog");
+			DB::TransactionScope tx(dbc.get());
+			createTempFileList(dbc.get(), tmp);
+			processChanges(dbc.get(), tmp);
+			dbc->execute("SET search_path = public, pg_catalog");
+		}
+	}
+}
+
diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp
deleted file mode 100644
index 8347d07..0000000
--- a/gentoobrowse-api/service/maintenanceimpl.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-#include "maintenanceimpl.h"
-#include <selectcommandUtil.impl.h>
-#include <tablepatch.h>
-#include <sqlWriter.h>
-#include <buffer.h>
-#include <scopeExit.h>
-#include <boost/filesystem/operations.hpp>
-#include <sql/maintenance/fileListCreateRaw.sql.h>
-#include <sql/maintenance/fileListCreate.sql.h>
-#include <sql/maintenance/fileListCreatePk.sql.h>
-#include "maintenance/categoryMetaProcessor.h"
-#include "maintenance/packageManifestProcessor.h"
-#include "maintenance/packageMetaProcessor.h"
-#include "maintenance/ebuildMetaProcessor.h"
-#include "maintenance/useGlobalProcessor.h"
-#include "maintenance/useLocalProcessor.h"
-#include "maintenance/useGroupProcessor.h"
-#include "maintenance/masksProcessor.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)"}
-9	use_grouped	{"(1,profiles)","(2,desc)","(3,%.desc)"}
-3	masks	{"(1,profiles)","(2,package.mask)"}
-
-8	package manifests	{"(3,Manifest)"}
-2	changelog	{"(3,ChangeLog)"}
-7	licenses	{"(1,licenses)"}
-11	news	{"(1,metadata)","(2,news)","(4,%.txt)"}
-*/
-
-namespace Gentoo {
-	namespace Service {
-		Maintenance::FileProcessor::~FileProcessor()
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::prepare(DB::Connection *)
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::apply(DB::Connection *)
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::tidy(DB::Connection *)
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::created(DB::Connection *, const boost::filesystem::path &, const boost::filesystem::path &)
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::modified(DB::Connection *, const boost::filesystem::path &, const boost::filesystem::path &)
-		{
-		}
-
-		void
-		Maintenance::FileProcessor::deleted(DB::Connection *, const boost::filesystem::path &)
-		{
-		}
-
-		template<typename T>
-		Maintenance::FileProcessorPtr
-		Maintenance::createFileProessor()
-		{
-			return FileProcessorPtr(new T());
-		}
-
-		Maintenance::Maintenance(IceTray::DatabasePoolPtr d) :
-			IceTray::AbstractDatabaseClient(d)
-		{
-			fpfs[CategoryMetaProcessor::FILETYPEID] = &createFileProessor<CategoryMetaProcessor>;
-			fpfs[PackageManifestProcessor::FILETYPEID] = &createFileProessor<PackageManifestProcessor>;
-			fpfs[PackageMetaProcessor::FILETYPEID] = &createFileProessor<PackageMetaProcessor>;
-			fpfs[EbuildMetaProcessor::FILETYPEID] = &createFileProessor<EbuildMetaProcessor>;
-			fpfs[UseGlobalProcessor::FILETYPEID] = &createFileProessor<UseGlobalProcessor>;
-			fpfs[UseLocalProcessor::FILETYPEID] = &createFileProessor<UseLocalProcessor>;
-			fpfs[UseGroupProcessor::FILETYPEID] = &createFileProessor<UseGroupProcessor>;
-			fpfs[MasksProcessor::FILETYPEID] = &createFileProessor<MasksProcessor>;
-		}
-
-		Maintenance::~Maintenance()
-		{
-		}
-
-		void
-		Maintenance::fileDeleted(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
-		{
-			// b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid
-			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) {
-					this->fileHandle(ft, fps, boost::bind(&FileProcessor::deleted, _1, dbc, fn));
-				});
-		}
-
-		void
-		Maintenance::fileChanged(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
-		{
-			// a.filename, a.filesize old_filesize, a.filetypeid old_filetypeid, a.moddate old_moddate, a.pathparts old_pathparts,a.repoid old_repoid,  b.filesize new_filesize, b.filetypeid new_filetypeid, b.moddate new_moddate, b.pathparts new_pathparts, b.repoid new_repoid
-			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto, auto, auto, auto, auto, auto) {
-					this->fileHandle(ft, fps, boost::bind(&FileProcessor::modified, _1, dbc, fn, tmp / fn));
-				});
-		}
-
-		void
-		Maintenance::fileCreated(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s)
-		{
-			// b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid
-			s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) {
-					this->fileHandle(ft, fps, boost::bind(&FileProcessor::created, _1, dbc, fn, tmp / fn));
-				});
-		}
-
-		void
-		Maintenance::fileHandle(int64_t ft, const FileProcessors * fps, const FileHandleFunc & f) const
-		{
-			auto i = fps->find(ft);
-			if (i != fps->end()) {
-				f(i->second);
-			}
-		}
-
-		void
-		Maintenance::createTempFileList(DB::Connection * dbc, const boost::filesystem::path & tmp)
-		{
-			boost::filesystem::remove_all(tmp);
-			boost::filesystem::create_directories(tmp);
-			dbc->select("SELECT name, path FROM gentoobrowse.repos")->forEachRow<std::string, std::string>([&tmp](auto n, auto p) {
-					boost::filesystem::create_symlink(p, tmp / n);
-				});
-			dbc->execute(sql::maintenance::fileListCreateRaw.getSql());
-			dbc->beginBulkUpload("filelistraw", "");
-			char buf[BUFSIZ];
-			for (boost::filesystem::recursive_directory_iterator d(tmp, boost::filesystem::symlink_option::recurse);
-					d != boost::filesystem::recursive_directory_iterator(); d++) {
-				if (boost::filesystem::is_regular_file(d->status())) {
-					auto len = snprintf(buf, BUFSIZ, "%s\t%ld\t%s\n",
-						d->path().lexically_relative(tmp).c_str(),
-						boost::filesystem::file_size(*d),
-						boost::posix_time::to_iso_extended_string(
-							boost::posix_time::from_time_t(boost::filesystem::last_write_time(*d))).c_str());
-					dbc->bulkUploadData(buf, len);
-				}
-			}
-			dbc->endBulkUpload(nullptr);
-		}
-
-		void
-		Maintenance::processChanges(DB::Connection * dbc, const boost::filesystem::path & tmp)
-		{
-			FileProcessors fps;
-			for (const auto & fpf : fpfs) {
-				fps[fpf.first] = fpf.second();
-			}
-			for (const auto & fp : fps) {
-				fp.second->prepare(dbc);
-			}
-			dbc->execute(sql::maintenance::fileListCreate.getSql());
-			dbc->execute(sql::maintenance::fileListCreatePk.getSql());
-			DB::TablePatch tp;
-			tp.src = "filelist";
-			tp.dest = "gentoobrowse.files";
-			tp.pk = {"filename"};
-			tp.cols = {"repoid", "filename", "filetypeid", "pathparts", "filesize", "moddate"};
-			tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, &fps, tmp, _1);
-			tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, &fps, tmp, _1);
-			tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, &fps, tmp, _1);
-			DB::StaticSqlWriter obpo("processOrder NULLS LAST");
-			tp.order = &obpo;
-			dbc->patchTable(&tp);
-			for (const auto & fp : fps) {
-				fp.second->apply(dbc);
-			}
-			dbc->execute("DROP TABLE filelist");
-			for (const auto & fp : fps) {
-				fp.second->tidy(dbc);
-			}
-		}
-
-		void
-		Maintenance::refreshPackageTree(const Ice::Current &)
-		{
-			auto tmp = boost::filesystem::temp_directory_path() / "import";
-			AdHoc::ScopeExit tidyTmp([&tmp]{
-					boost::system::error_code ec;
-					boost::filesystem::remove_all(tmp, ec);
-				});
-			auto dbc = db->get();
-			dbc->execute("SET search_path = gentoobrowse, pg_catalog");
-			DB::TransactionScope tx(dbc.get());
-			createTempFileList(dbc.get(), tmp);
-			processChanges(dbc.get(), tmp);
-			dbc->execute("SET search_path = public, pg_catalog");
-		}
-	}
-}
-
-- 
cgit v1.2.3