aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 10:28:23 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 10:35:03 +0100
commit781d3423f2b70958616ac9b5b36621d9c28f7ba9 (patch)
tree83f3f31a125689717cec9d1d9850ac4d7db9923c
parent1d7b030ddca58f5dd977d5429bab5034789c5a99 (diff)
downloadpaludis-781d3423f2b70958616ac9b5b36621d9c28f7ba9.tar.gz
paludis-781d3423f2b70958616ac9b5b36621d9c28f7ba9.tar.xz
World rewriting for PortageEnvironment
-rw-r--r--paludis/environments/portage/portage_environment.cc21
-rw-r--r--paludis/environments/portage/portage_environment.hh2
-rw-r--r--paludis/environments/portage/portage_environment_TEST.cc32
-rwxr-xr-xpaludis/environments/portage/portage_environment_TEST_setup.sh12
4 files changed, 54 insertions, 13 deletions
diff --git a/paludis/environments/portage/portage_environment.cc b/paludis/environments/portage/portage_environment.cc
index 38d676d..247da9b 100644
--- a/paludis/environments/portage/portage_environment.cc
+++ b/paludis/environments/portage/portage_environment.cc
@@ -120,7 +120,7 @@ namespace paludis
done_hooks(false),
overlay_importance(10),
package_database(new PackageDatabase(e)),
- world_file("/var/lib/portage/world"),
+ world_file(s + "/var/lib/portage/world"),
format_key(new LiteralMetadataValueKey<std::string>("format", "Format", mkt_significant, "portage")),
config_location_key(new LiteralMetadataValueKey<FSEntry>("conf_dir", "Config dir", mkt_normal,
conf_dir)),
@@ -929,12 +929,13 @@ PortageEnvironment::_add_string_to_world(const std::string & s) const
world.rewrite();
}
-void
+bool
PortageEnvironment::_remove_string_from_world(const std::string & s) const
{
Lock l(_imp->world_mutex);
Context context("When removing '" + s + "' from world file '" + stringify(_imp->world_file) + "':");
+ bool result(false);
using namespace std::tr1::placeholders;
@@ -950,9 +951,18 @@ PortageEnvironment::_remove_string_from_world(const std::string & s) const
value_for<n::type>(sft_simple)
));
- world.remove(s);
+ result = world.remove(s);
world.rewrite();
}
+
+ return result;
+}
+
+void
+PortageEnvironment::update_config_files_for_package_move(const PackageDepSpec & s, const QualifiedPackageName & n) const
+{
+ if (_remove_string_from_world(stringify(s)))
+ _add_string_to_world(stringify(PartiallyMadePackageDepSpec(s).package(n)));
}
void
@@ -1020,8 +1030,3 @@ PortageEnvironment::repository_from_new_config_file(const FSEntry &)
throw InternalError(PALUDIS_HERE, "can't create repositories on the fly for PortageEnvironment");
}
-void
-PortageEnvironment::update_config_files_for_package_move(const PackageDepSpec &, const QualifiedPackageName &) const
-{
-}
-
diff --git a/paludis/environments/portage/portage_environment.hh b/paludis/environments/portage/portage_environment.hh
index e172ee7..1aa2617 100644
--- a/paludis/environments/portage/portage_environment.hh
+++ b/paludis/environments/portage/portage_environment.hh
@@ -77,7 +77,7 @@ namespace paludis
void _load_atom_file(const FSEntry &, I_, const std::string &, const bool);
void _add_string_to_world(const std::string &) const;
- void _remove_string_from_world(const std::string &) const;
+ bool _remove_string_from_world(const std::string &) const;
protected:
virtual void need_keys_added() const;
diff --git a/paludis/environments/portage/portage_environment_TEST.cc b/paludis/environments/portage/portage_environment_TEST.cc
index 6dd1ac6..57d1123 100644
--- a/paludis/environments/portage/portage_environment_TEST.cc
+++ b/paludis/environments/portage/portage_environment_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -17,14 +17,13 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "portage_environment.hh"
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+#include <paludis/environments/portage/portage_environment.hh>
#include <paludis/util/join.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/options.hh>
+#include <paludis/util/safe_ifstream.hh>
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/dep_spec.hh>
@@ -36,6 +35,8 @@
#include <paludis/selection.hh>
#include <paludis/metadata_key.hh>
#include <paludis/choice.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
using namespace paludis;
using namespace test;
@@ -185,5 +186,28 @@ namespace test_cases
TEST_CHECK(! accept_keyword(env, KeywordName("foo"), *id5));
}
} test_accept_keywords;
+
+ struct TestWorldUpdates : TestCase
+ {
+ TestWorldUpdates() : TestCase("world updates") { }
+
+ void run()
+ {
+ TestPortageEnvironment env("portage_environment_TEST_dir/world");
+ FSEntry w(FSEntry::cwd() / "portage_environment_TEST_dir" / "world" / "var" / "lib" / "portage" / "world");
+
+ env.update_config_files_for_package_move(make_package_dep_spec(PartiallyMadePackageDepSpecOptions())
+ .package(QualifiedPackageName("cat/before")),
+ QualifiedPackageName("cat/after"));
+
+ SafeIFStream f(w);
+ std::string ff((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(ff,
+ "cat/unchanged\n"
+ "cat/alsounchanged\n"
+ "cat/after\n"
+ );
+ }
+ } world_updates_test;
}
diff --git a/paludis/environments/portage/portage_environment_TEST_setup.sh b/paludis/environments/portage/portage_environment_TEST_setup.sh
index 957d1ca..d789c77 100755
--- a/paludis/environments/portage/portage_environment_TEST_setup.sh
+++ b/paludis/environments/portage/portage_environment_TEST_setup.sh
@@ -67,3 +67,15 @@ cat <<"END" > known_use_expand_names/${SYSCONFDIR}/portage/package.use
cat-one/pkg-one -foo_cards_two foo_cards_three
END
+mkdir -p world/{${SYSCONFDIR},var/lib/portage}
+ln -s $(pwd )/profile world/${SYSCONFDIR}/make.profile
+cat <<END > world/${SYSCONFDIR}/make.conf
+PORTDIR="`pwd`/repo"
+END
+cat <<END > world/var/lib/portage/world
+cat/unchanged
+cat/before
+cat/alsounchanged
+END
+
+