aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 10:12:54 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 10:34:54 +0100
commit1d7b030ddca58f5dd977d5429bab5034789c5a99 (patch)
tree398a06f3ec8676941dce7aef2b21f724cee6b59a
parent16d0f528e226e88b28286d8b52a49dbb41ad752b (diff)
downloadpaludis-1d7b030ddca58f5dd977d5429bab5034789c5a99.tar.gz
paludis-1d7b030ddca58f5dd977d5429bab5034789c5a99.tar.xz
Update PaludisEnvironment::world for package moves
-rw-r--r--.gitignore1
-rw-r--r--paludis/environments/paludis/Makefile.am20
-rw-r--r--paludis/environments/paludis/paludis_environment.cc3
-rw-r--r--paludis/environments/paludis/world.cc18
-rw-r--r--paludis/environments/paludis/world.hh9
-rw-r--r--paludis/environments/paludis/world_TEST.cc61
-rwxr-xr-xpaludis/environments/paludis/world_TEST_cleanup.sh9
-rwxr-xr-xpaludis/environments/paludis/world_TEST_setup.sh12
8 files changed, 123 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 5210215..8911e38 100644
--- a/.gitignore
+++ b/.gitignore
@@ -200,6 +200,7 @@ paludis-*.*.*.tar.bz2
/paludis/environments/adapted/adapted_environment_TEST
/paludis/environments/no_config/no_config_environment_TEST
/paludis/environments/paludis/paludis_environment_TEST
+/paludis/environments/paludis/world_TEST
/paludis/environments/portage/portage_environment_TEST
/paludis/fetchers/doftp
/paludis/fetchers/dohttp
diff --git a/paludis/environments/paludis/Makefile.am b/paludis/environments/paludis/Makefile.am
index bf0ddc0..7cb9fd7 100644
--- a/paludis/environments/paludis/Makefile.am
+++ b/paludis/environments/paludis/Makefile.am
@@ -49,12 +49,17 @@ EXTRA_DIST = \
paludis_environment_TEST_setup.sh \
paludis_environment_TEST.cc \
paludis_environment_TEST_cleanup.sh \
+ world_TEST_setup.sh \
+ world_TEST.cc \
+ world_TEST_cleanup.sh \
$(BUILT_SOURCES)
-TESTS = paludis_environment_TEST
+TESTS = paludis_environment_TEST world_TEST
check_PROGRAMS = $(TESTS)
-check_SCRIPTS = paludis_environment_TEST_setup.sh paludis_environment_TEST_cleanup.sh
+check_SCRIPTS = \
+ paludis_environment_TEST_setup.sh paludis_environment_TEST_cleanup.sh \
+ world_TEST_setup.sh world_TEST_cleanup.sh
paludis_environment_TEST_SOURCES = paludis_environment_TEST.cc
@@ -67,3 +72,14 @@ paludis_environment_TEST_LDADD = \
paludis_environment_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+world_TEST_SOURCES = world_TEST.cc
+
+world_TEST_LDADD = \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
+ $(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
+ $(DYNAMIC_LD_LIBS)
+
+world_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+
diff --git a/paludis/environments/paludis/paludis_environment.cc b/paludis/environments/paludis/paludis_environment.cc
index 1186bf2..9bbb118 100644
--- a/paludis/environments/paludis/paludis_environment.cc
+++ b/paludis/environments/paludis/paludis_environment.cc
@@ -564,7 +564,8 @@ PaludisEnvironment::repository_from_new_config_file(const FSEntry & f)
}
void
-PaludisEnvironment::update_config_files_for_package_move(const PackageDepSpec &, const QualifiedPackageName &) const
+PaludisEnvironment::update_config_files_for_package_move(const PackageDepSpec & s, const QualifiedPackageName & n) const
{
+ _imp->config->world()->update_config_files_for_package_move(s, n);
}
diff --git a/paludis/environments/paludis/world.cc b/paludis/environments/paludis/world.cc
index f78daca..e642547 100644
--- a/paludis/environments/paludis/world.cc
+++ b/paludis/environments/paludis/world.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 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
@@ -127,16 +127,17 @@ World::_add_string_to_world(const std::string & n) const
world.rewrite();
}
-void
+bool
World::_remove_string_from_world(const std::string & n) const
{
using namespace std::tr1::placeholders;
+ bool result(false);
if (! _imp->maybe_world_file)
{
Log::get_instance()->message("paludis_environment.world.no_world", ll_warning, lc_context)
<< "Not removing '" << n << "' from world because no world file has been configured";
- return;
+ return result;
}
Lock l(_imp->mutex);
@@ -154,9 +155,18 @@ World::_remove_string_from_world(const std::string & n) const
value_for<n::type>(sft_simple)
));
- world.remove(n);
+ result = world.remove(n);
world.rewrite();
}
+
+ return result;
+}
+
+void
+World::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)));
}
const std::tr1::shared_ptr<const SetSpecTree>
diff --git a/paludis/environments/paludis/world.hh b/paludis/environments/paludis/world.hh
index ba1d620..5665e27 100644
--- a/paludis/environments/paludis/world.hh
+++ b/paludis/environments/paludis/world.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 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
@@ -32,12 +32,12 @@ namespace paludis
{
namespace paludis_environment
{
- class World :
+ class PALUDIS_VISIBLE World :
private PrivateImplementationPattern<World>
{
private:
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;
public:
World(const Environment * const, const std::tr1::shared_ptr<const FSEntry> &);
@@ -52,6 +52,9 @@ namespace paludis
void remove_from_world(const QualifiedPackageName &) const;
std::tr1::shared_ptr<const FSEntry> location_if_set() const;
+
+ void update_config_files_for_package_move(
+ const PackageDepSpec &, const QualifiedPackageName &) const;
};
}
}
diff --git a/paludis/environments/paludis/world_TEST.cc b/paludis/environments/paludis/world_TEST.cc
new file mode 100644
index 0000000..3a4e10b
--- /dev/null
+++ b/paludis/environments/paludis/world_TEST.cc
@@ -0,0 +1,61 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/environments/paludis/world.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/safe_ifstream.hh>
+#include <paludis/util/options.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <iterator>
+#include <cstdlib>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ struct TestWorldUpdates : TestCase
+ {
+ TestWorldUpdates() : TestCase("world updates") { }
+
+ void run()
+ {
+ std::tr1::shared_ptr<FSEntry> w(new FSEntry(FSEntry::cwd() / "world_TEST_dir" / "world"));
+
+ {
+ TestEnvironment env;
+ paludis_environment::World world(&env, w);
+ world.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/paludis/world_TEST_cleanup.sh b/paludis/environments/paludis/world_TEST_cleanup.sh
new file mode 100755
index 0000000..a02051a
--- /dev/null
+++ b/paludis/environments/paludis/world_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d world_TEST_dir ] ; then
+ rm -fr world_TEST_dir
+else
+ true
+fi
+
diff --git a/paludis/environments/paludis/world_TEST_setup.sh b/paludis/environments/paludis/world_TEST_setup.sh
new file mode 100755
index 0000000..f81a62b
--- /dev/null
+++ b/paludis/environments/paludis/world_TEST_setup.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir world_TEST_dir || exit 2
+cd world_TEST_dir || exit 3
+
+cat <<END > world
+cat/unchanged
+cat/before
+cat/alsounchanged
+END
+