From 86f5dbff95f030d397d79546252fc0944bdc4095 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Nov 2017 13:58:53 +0000 Subject: Don't try to be too clever when processing updates, as there is no guarantee the ebuilds will get moved in the same commit window and we don't (yet) support git move detection --- .../service/maintenance/updatesProcessor.cpp | 74 +++++++++------------- .../sql/maintenance/updatesMovePackages.sql | 8 --- .../profiles/use.local.desc | 1 + gentoobrowse-api/unittests/testMaintenance.cpp | 12 ++-- 4 files changed, 37 insertions(+), 58 deletions(-) delete mode 100644 gentoobrowse-api/service/sql/maintenance/updatesMovePackages.sql diff --git a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp index 530c445..77e55e1 100644 --- a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,9 +33,9 @@ namespace Gentoo { public: UpdatesPatch(DB::Connection * db) : categoryInsert(sql::maintenance::categoryInsert.modify(db)), + packageInsert(sql::maintenance::packageInsert.modify(db)), findPackage(sql::portage::findPackage.select(db)), - movePackages(sql::maintenance::updatesMovePackages.modify(db)), - moveUserPackages(sql::maintenance::updatesMoveUserPackages.modify(db)), + updatesMoveUserPackages(sql::maintenance::updatesMoveUserPackages.modify(db)), changes(nullptr), updatePacks("updatePack") { @@ -63,9 +63,9 @@ namespace Gentoo { DB::ModifyCommandPtr drop; DB::ModifyCommandPtr categoryInsert; + DB::ModifyCommandPtr packageInsert; DB::SelectCommandPtr findPackage; - DB::ModifyCommandPtr movePackages; - DB::ModifyCommandPtr moveUserPackages; + DB::ModifyCommandPtr updatesMoveUserPackages; ChangeSet * changes; Utils::EntityWhereFilter updatePacks; @@ -73,51 +73,37 @@ namespace Gentoo { move(DB::SelectCommandPtr s) { s->forEachRow([this](auto catfrom, auto catto, auto namefrom, auto nameto, auto) { - findPackage->bindParamS(0, catto); - findPackage->bindParamS(1, nameto); - if (findPackage->fetch()) { // Does target already exist? - // Merge - moveUserPackages->bindParamS(0, catfrom); - moveUserPackages->bindParamS(1, namefrom); - moveUserPackages->bindParamS(2, catto); - moveUserPackages->bindParamS(3, nameto); - moveUserPackages->execute(); - } - else { - // Move + 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(); - movePackages->bindParamS(0, nameto); - movePackages->bindParamS(1, namefrom); - movePackages->bindParamS(2, catfrom); - movePackages->bindParamS(3, catto); - movePackages->execute(); - // Move and/or merge file list entries - for(auto changei = changes->begin(); changei != changes->end();) { - auto & pp = changei->second.pathParts; - if (pp.size() == 4 && pp[0] == "metadata" && pp[1] == "md5-cache" && pp[2] == catfrom && boost::algorithm::starts_with(pp[3], namefrom + "-")) { - auto cd = changei->second; - cd.pathParts[2] = catto; - cd.pathParts[3] = nameto + cd.pathParts[3].substr(namefrom.length()); - auto path = boost::algorithm::join(cd.pathParts, "/"); - auto target = changes->find(path); - if (target == changes->end()) { - changes->insert({ path, cd }); - } - else if (cd.changeType == GIT_DELTA_DELETED && target->second.changeType == GIT_DELTA_ADDED) { - target->second.changeType = GIT_DELTA_MODIFIED; - } - changei = changes->erase(changei); - } - else { - changei++; - } - } + // Create package + packageInsert->bindParamS(0, nameto); + packageInsert->bindParamS(1, "Created by package move"); + packageInsert->bindParamS(2, nameto); + packageInsert->bindParamS(3, catto); + packageInsert->execute(); } - while (findPackage->fetch()) ; + 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; + } }; void diff --git a/gentoobrowse-api/service/sql/maintenance/updatesMovePackages.sql b/gentoobrowse-api/service/sql/maintenance/updatesMovePackages.sql deleted file mode 100644 index 1dfe419..0000000 --- a/gentoobrowse-api/service/sql/maintenance/updatesMovePackages.sql +++ /dev/null @@ -1,8 +0,0 @@ -UPDATE gentoobrowse.packages p SET - name = ?, - categoryid = cn.categoryid -FROM gentoobrowse.categories co, gentoobrowse.categories cn -WHERE p.name = ? -AND p.categoryid = co.categoryid -AND co.name = ? -AND cn.name = ? diff --git a/gentoobrowse-api/unittests/fixtures/756569aa764177340726dd3d40b41d89b11b20c7/profiles/use.local.desc b/gentoobrowse-api/unittests/fixtures/756569aa764177340726dd3d40b41d89b11b20c7/profiles/use.local.desc index 0240b4d..aea3813 100644 --- a/gentoobrowse-api/unittests/fixtures/756569aa764177340726dd3d40b41d89b11b20c7/profiles/use.local.desc +++ b/gentoobrowse-api/unittests/fixtures/756569aa764177340726dd3d40b41d89b11b20c7/profiles/use.local.desc @@ -1,6 +1,7 @@ # This file is deprecated as per GLEP 56 in favor of metadata.xml. # Please add your descriptions to your package's metadata.xml ONLY. # * generated automatically using pmaint * +# Changed size with this line app-accessibility/brltty:api - build brltty's application program interface app-accessibility/brltty:beeper - support the console tone generator diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index 2bdba64..ab9786d 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -277,16 +277,16 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository ) 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); } - BOOST_TEST_CONTEXT("And it maintained its original packageId, but changed categoryId") { + 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, 9); + 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); } - BOOST_TEST_CONTEXT("Original ebuilds in moved package were not deleted and replaced") { - 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); + 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); } } BOOST_TEST_CONTEXT("Change log was imported correctly") { -- cgit v1.2.3