diff options
5 files changed, 72 insertions, 0 deletions
| diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index 7cbd902..ef849fb 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -4,8 +4,10 @@  #include <selectcommandUtil.impl.h>  #include <sqlWriter.h>  #include <boost/filesystem/operations.hpp> +#include <boost/algorithm/string/join.hpp>  #include <glibmm/regex.h>  #include <tablepatch.h> +#include "depend.h"  #include "utils/fileUtils.h"  #include "utils/dbUtils.h"  #include "utils/ebuildCacheParser.h" @@ -19,6 +21,7 @@  #include <sql/maintenance/ebuildInsert.sql.h>  #include <sql/maintenance/ebuildUpdate.sql.h>  #include <sql/maintenance/ebuildDelete.sql.h> +#include <sql/maintenance/ebuildDeps.sql.h>  namespace U = Gentoo::Utils;  using namespace Gentoo::Utils::File; @@ -114,6 +117,32 @@ namespace Gentoo {  			t.cols = { "ebuildid", "arch" };  			t.where = &ewf;  			dbc->patchTable(&t); +			// Dependencies +			t.pk = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; +			t.cols = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; +			t.where = &ewf; +			DB::StaticSqlWriter s(sql::maintenance::ebuildDeps.getSql()); +			t.srcExpr = &s; +			auto ins = Utils::Database::namedTemp(dbc, "tmpEbuildDeps", { +						{ "ebuildId", "int" }, // 1 +						{ "category", "text" }, // 0 +						{ "package", "text" }, // 4 +						{ "version", "text" }, // 6 +						{ "slot", "text" }, // 5 +						{ "flags", "text" }, // 2 +						{ "op", "text" } // 3 +					}); +			ins.second->bindParamI(1, ebuildId); +			auto db = Portage::Utils::Depend::parse(ecp.get("DEPEND").value_or("")); +			t.dest = "gentoobrowse.ebuild_deps"; +			insertDeps(ins.second.get(), db); +			dbc->patchTable(&t); +			dbc->execute("TRUNCATE TABLE tmpEbuildDeps"); +			auto dr = Portage::Utils::Depend::parse(ecp.get("RDEPEND").value_or("")); +			t.dest = "gentoobrowse.ebuild_rdeps"; +			insertDeps(ins.second.get(), dr); +			dbc->patchTable(&t); +			Utils::Database::drop(dbc, "tmpEbuildDeps");  			if (newest) {  				// HOMEPAGE  				U::EntityWhereFilter pwf("packageId", packageId); @@ -132,6 +161,26 @@ namespace Gentoo {  			}  		} +		template<typename T> +		const T & operator|=(const IceUtil::Optional<T> & a, const T & b) +		{ +			return a ? *a : b; +		} + +		void +		EbuildMetaProcessor::insertDeps(DB::ModifyCommand * ins, const std::vector<Gentoo::DependencyPtr> & deps) const +		{ +			for (const auto & d : deps) { +				ins->bindParamS(0, d->category); +				ins->bindParamS(2, boost::algorithm::join(d->use, ",")); +				ins->bindParamS(3, d->op |= std::string()); +				ins->bindParamS(4, d->package); +				ins->bindParamS(5, d->slot |= std::string()); +				ins->bindParamS(6, d->version |= std::string()); +				ins->execute(); +			} +		} +  		void  		EbuildMetaProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const  		{ diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index 3cd6ba9..fb9d48c 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -3,6 +3,7 @@  #include "../maintenanceimpl.h"  #include "utils/ebuildCacheParser.h" +#include <portage-models.h>  #include <connection.h>  #include <modifycommand.h>  #include <boost/filesystem/path.hpp> @@ -19,6 +20,7 @@ namespace Gentoo {  			private:  				void perEbuildUpdates(DB::Connection * dbc, const Utils::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) const; +				void insertDeps(DB::ModifyCommand * dbc, const std::vector<Gentoo::DependencyPtr> &) const;  		};  	}  } diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql b/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql new file mode 100644 index 0000000..801c877 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql @@ -0,0 +1,7 @@ +( +	SELECT DISTINCT ebuildid, packageid, e.version versionspec, flags, slot, op +	FROM gentoobrowse.categories c, gentoobrowse.packages p, tmpEbuildDeps e +	WHERE c.categoryid = p.categoryid +	AND c.name = e.category +	AND p.name = e.package +) diff --git a/gentoobrowse-api/service/utils/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp index c368c7a..1b38da6 100644 --- a/gentoobrowse-api/service/utils/dbUtils.cpp +++ b/gentoobrowse-api/service/utils/dbUtils.cpp @@ -19,6 +19,17 @@ namespace Gentoo {  				return false;  			} +			void +			bindOptionalS(DB::Command * db, unsigned int c, const IceUtil::Optional<std::string> & v) +			{ +				if (v) { +					db->bindParamS(c, *v); +				} +				else { +					db->bindNull(c); +				} +			} +  			std::string  			emptyClone(DB::Connection * db, const std::string & orig)  			{ diff --git a/gentoobrowse-api/service/utils/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h index 95ae868..b533783 100644 --- a/gentoobrowse-api/service/utils/dbUtils.h +++ b/gentoobrowse-api/service/utils/dbUtils.h @@ -4,11 +4,14 @@  #include <command.h>  #include <modifycommand.h>  #include <connection.h> +#include <IceUtil/Exception.h> +#include <IceUtil/Optional.h>  namespace Gentoo {  	namespace Utils {  		namespace Database {  			bool bindOptionalsS(DB::Command * db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs); +			void bindOptionalS(DB::Command * db, unsigned int c, const IceUtil::Optional<std::string> & v);  			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); | 
