aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-26 11:02:12 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-26 11:02:12 +0000
commit979cf67ff1d92626a2e95e88d57759e5d9b6c38a (patch)
tree705d5a9f80280cfe9b074f3c63045a39fbe45b0e
parent238c11a3272f26b61204681aa1cfb5cb404e1389 (diff)
downloadpaludis-979cf67ff1d92626a2e95e88d57759e5d9b6c38a.tar.gz
paludis-979cf67ff1d92626a2e95e88d57759e5d9b6c38a.tar.xz
DepList::add() is now properly transactional again
-rw-r--r--paludis/dep_list.cc61
-rw-r--r--paludis/dep_list_TEST.cc52
2 files changed, 77 insertions, 36 deletions
diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc
index 022fafd..f907772 100644
--- a/paludis/dep_list.cc
+++ b/paludis/dep_list.cc
@@ -146,37 +146,48 @@ DepList::~DepList()
void
DepList::add(DepAtom::ConstPointer atom)
{
+ std::list<DepListEntry> save_merge_list(_implementation->merge_list.begin(),
+ _implementation->merge_list.end());
+
_implementation->merge_list_insert_pos = _implementation->merge_list.end();
_add(atom);
- std::list<DepListEntry>::iterator i(_implementation->merge_list.begin());
- _implementation->merge_list_insert_pos = _implementation->merge_list.end();
- while (i != _implementation->merge_list.end())
+ try
{
- if (! i->get<dle_has_predeps>())
- throw InternalError(PALUDIS_HERE, "dle_has_predeps not set for " + stringify(*i));
-
- else if (! i->get<dle_has_trypredeps>())
- {
- _implementation->current_package = &*i;
- _add_in_role(DepParser::parse(
- _implementation->environment->package_database()->fetch_metadata(
- PackageDatabaseEntry(i->get<dle_name>(), i->get<dle_version>(),
- i->get<dle_repository>()))->get(vmk_rdepend)), "RDEPEND");
- i->set<dle_has_trypredeps>(true);
- }
-
- else if (! i->get<dle_has_postdeps>())
+ std::list<DepListEntry>::iterator i(_implementation->merge_list.begin());
+ _implementation->merge_list_insert_pos = _implementation->merge_list.end();
+ while (i != _implementation->merge_list.end())
{
- _implementation->current_package = &*i;
- _add_in_role(DepParser::parse(
- _implementation->environment->package_database()->fetch_metadata(
- PackageDatabaseEntry(i->get<dle_name>(), i->get<dle_version>(),
- i->get<dle_repository>()))->get(vmk_pdepend)), "PDEPEND");
- i->set<dle_has_postdeps>(true);
+ if (! i->get<dle_has_predeps>())
+ throw InternalError(PALUDIS_HERE, "dle_has_predeps not set for " + stringify(*i));
+
+ else if (! i->get<dle_has_trypredeps>())
+ {
+ _implementation->current_package = &*i;
+ _add_in_role(DepParser::parse(
+ _implementation->environment->package_database()->fetch_metadata(
+ PackageDatabaseEntry(i->get<dle_name>(), i->get<dle_version>(),
+ i->get<dle_repository>()))->get(vmk_rdepend)), "RDEPEND");
+ i->set<dle_has_trypredeps>(true);
+ }
+
+ else if (! i->get<dle_has_postdeps>())
+ {
+ _implementation->current_package = &*i;
+ _add_in_role(DepParser::parse(
+ _implementation->environment->package_database()->fetch_metadata(
+ PackageDatabaseEntry(i->get<dle_name>(), i->get<dle_version>(),
+ i->get<dle_repository>()))->get(vmk_pdepend)), "PDEPEND");
+ i->set<dle_has_postdeps>(true);
+ }
+ else
+ ++i;
}
- else
- ++i;
+ }
+ catch (...)
+ {
+ _implementation->merge_list.swap(save_merge_list);
+ throw;
}
}
diff --git a/paludis/dep_list_TEST.cc b/paludis/dep_list_TEST.cc
index 061679b..fc602b2 100644
--- a/paludis/dep_list_TEST.cc
+++ b/paludis/dep_list_TEST.cc
@@ -264,24 +264,54 @@ namespace test_cases
FakeRepository::Pointer repo(new FakeRepository(RepositoryName("repo")));
env.package_database()->add_repository(repo);
- repo->add_version("i", "one", "1")->set(vmk_depend, "i/two i/three");
- repo->add_version("i", "two", "1")->set(vmk_depend, "i/four");
- repo->add_version("i", "three", "1")->set(vmk_depend, "i/four i/two");
- repo->add_version("i", "four", "1");
- repo->add_version("i", "five", "1")->set(vmk_depend, "i/six i/seven");
- repo->add_version("i", "six", "1");
- repo->add_version("i", "seven", "1")->set(vmk_depend, "i/doesnotexist");
+ repo->add_version("cat", "one", "1")->set(vmk_depend, "cat/two cat/three");
+ repo->add_version("cat", "two", "1")->set(vmk_depend, "cat/four");
+ repo->add_version("cat", "three", "1")->set(vmk_depend, "cat/four cat/two");
+ repo->add_version("cat", "four", "1");
+ repo->add_version("cat", "five", "1")->set(vmk_depend, "cat/six cat/seven");
+ repo->add_version("cat", "six", "1");
+ repo->add_version("cat", "seven", "1")->set(vmk_depend, "cat/doesnotexist");
DepList d(&env);
- d.add(DepParser::parse("i/one"));
+ d.add(DepParser::parse("cat/one"));
TEST_CHECK_EQUAL(join(d.begin(), d.end(), " "),
- "i/four-1:0::repo i/two-1:0::repo i/three-1:0::repo i/one-1:0::repo");
+ "cat/four-1:0::repo cat/two-1:0::repo cat/three-1:0::repo cat/one-1:0::repo");
- TEST_CHECK_THROWS(d.add(DepParser::parse("i/five")), DepListError);
+ TEST_CHECK_THROWS(d.add(DepParser::parse("cat/five")), DepListError);
TEST_CHECK_EQUAL(join(d.begin(), d.end(), " "),
- "i/four-1:0::repo i/two-1:0::repo i/three-1:0::repo i/one-1:0::repo");
+ "cat/four-1:0::repo cat/two-1:0::repo cat/three-1:0::repo cat/one-1:0::repo");
}
} test_dep_list_transactional_add;
+
+ struct DepListTestCaseTransactionalAddPost : TestCase
+ {
+ DepListTestCaseTransactionalAddPost() : TestCase("dep list transactional add post") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ FakeRepository::Pointer repo(new FakeRepository(RepositoryName("repo")));
+ env.package_database()->add_repository(repo);
+
+ repo->add_version("cat", "one", "1")->set(vmk_depend, "cat/two cat/three");
+ repo->add_version("cat", "two", "1")->set(vmk_depend, "cat/four");
+ repo->add_version("cat", "three", "1")->set(vmk_depend, "cat/four cat/two");
+ repo->add_version("cat", "four", "1");
+ repo->add_version("cat", "five", "1")->set(vmk_depend, "cat/six cat/seven");
+ repo->add_version("cat", "six", "1");
+ repo->add_version("cat", "seven", "1")->set(vmk_pdepend, "cat/doesnotexist");
+
+ DepList d(&env);
+ d.add(DepParser::parse("cat/one"));
+ TEST_CHECK_EQUAL(join(d.begin(), d.end(), " "),
+ "cat/four-1:0::repo cat/two-1:0::repo cat/three-1:0::repo cat/one-1:0::repo");
+
+ TEST_CHECK_THROWS(d.add(DepParser::parse("cat/five")), DepListError);
+
+ TEST_CHECK_EQUAL(join(d.begin(), d.end(), " "),
+ "cat/four-1:0::repo cat/two-1:0::repo cat/three-1:0::repo cat/one-1:0::repo");
+ }
+ } test_dep_list_transactional_add_post;
}