aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-06 00:43:21 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-06 00:43:21 +0000
commitfc005ba34a43832744300c75865d3a7062583b34 (patch)
treef2bcc34df5da6406497036a67e3660f07493cf9c
parent0ff13cd5eff8dcfd25b184a1e92d3362ec8f3c5b (diff)
downloadpaludis-fc005ba34a43832744300c75865d3a7062583b34.tar.gz
paludis-fc005ba34a43832744300c75865d3a7062583b34.tar.xz
Portage doesn't always add a newline to the end of the world file. Work with this stupidity.
-rw-r--r--paludis/repositories/vdb/vdb_repository.cc28
-rw-r--r--paludis/repositories/vdb/vdb_repository_TEST.cc122
-rwxr-xr-xpaludis/repositories/vdb/vdb_repository_TEST_setup.sh18
3 files changed, 168 insertions, 0 deletions
diff --git a/paludis/repositories/vdb/vdb_repository.cc b/paludis/repositories/vdb/vdb_repository.cc
index 0f8e151..24ebab9 100644
--- a/paludis/repositories/vdb/vdb_repository.cc
+++ b/paludis/repositories/vdb/vdb_repository.cc
@@ -900,6 +900,9 @@ VDBRepository::invalidate() const
void
VDBRepository::add_to_world(const QualifiedPackageName & n) const
{
+ Context context("When adding '" + stringify(n) + "' to world file '" +
+ stringify(_imp->world_file) + "':");
+
bool found(false);
if (_imp->world_file.exists())
@@ -917,12 +920,37 @@ VDBRepository::add_to_world(const QualifiedPackageName & n) const
if (! found)
{
+ /* portage is retarded, and doesn't ensure that the last entry in world has
+ * a newline character after it. */
+ bool world_file_needs_newline(false);
+ {
+ std::ifstream world(stringify(_imp->world_file).c_str(), std::ios::in);
+ if (world)
+ {
+ world.seekg(0, std::ios::end);
+ if (0 != world.tellg())
+ {
+ world.seekg(-1, std::ios::end);
+ if ('\n' != world.get())
+ world_file_needs_newline = true;
+ }
+ }
+ }
+
+ if (world_file_needs_newline)
+ Log::get_instance()->message(ll_warning, lc_no_context, "World file '"
+ + stringify(_imp->world_file) + "' lacks final newline");
+
std::ofstream world(stringify(_imp->world_file).c_str(), std::ios::out | std::ios::app);
if (! world)
Log::get_instance()->message(ll_warning, lc_no_context, "Cannot append to world file '"
+ stringify(_imp->world_file) + "', skipping world update");
else
+ {
+ if (world_file_needs_newline)
+ world << std::endl;
world << n << std::endl;
+ }
}
}
diff --git a/paludis/repositories/vdb/vdb_repository_TEST.cc b/paludis/repositories/vdb/vdb_repository_TEST.cc
index ca0b523..48bfe29 100644
--- a/paludis/repositories/vdb/vdb_repository_TEST.cc
+++ b/paludis/repositories/vdb/vdb_repository_TEST.cc
@@ -22,6 +22,8 @@
#include <paludis/test_environment.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
+#include <fstream>
+#include <iterator>
using namespace test;
using namespace paludis;
@@ -112,5 +114,125 @@ namespace test_cases
TEST_CHECK(repo->query_use(UseFlagName("flag4"), &e2) == use_unspecified);
}
} test_vdb_repository_query_use;
+
+ /**
+ * \test Test VDBRepository add_to_world.
+ */
+ struct VDBRepositoryAddToWorldNewFileTest : TestCase
+ {
+ VDBRepositoryAddToWorldNewFileTest() : TestCase("add to world (new file)") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "vdb");
+ keys->insert("location", "vdb_repository_TEST_dir/repo1");
+ keys->insert("world", "vdb_repository_TEST_dir/world-new-file");
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ repo->add_to_world(QualifiedPackageName("cat-one/foofoo"));
+ std::ifstream world("vdb_repository_TEST_dir/world-new-file");
+ std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(world_content, "cat-one/foofoo\n");
+ }
+ } test_vdb_repository_add_to_world_new_file;
+
+ /**
+ * \test Test VDBRepository add_to_world.
+ */
+ struct VDBRepositoryAddToWorldEmptyFileTest : TestCase
+ {
+ VDBRepositoryAddToWorldEmptyFileTest() : TestCase("add to world (empty file)") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "vdb");
+ keys->insert("location", "vdb_repository_TEST_dir/repo1");
+ keys->insert("world", "vdb_repository_TEST_dir/world-empty");
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ repo->add_to_world(QualifiedPackageName("cat-one/foofoo"));
+ std::ifstream world("vdb_repository_TEST_dir/world-empty");
+ std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(world_content, "cat-one/foofoo\n");
+ }
+ } test_vdb_repository_add_to_world_empty_file;
+
+ /**
+ * \test Test VDBRepository add_to_world.
+ */
+ struct VDBRepositoryAddToWorldNoMatchTest : TestCase
+ {
+ VDBRepositoryAddToWorldNoMatchTest() : TestCase("add to world (no match)") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "vdb");
+ keys->insert("location", "vdb_repository_TEST_dir/repo1");
+ keys->insert("world", "vdb_repository_TEST_dir/world-no-match");
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ repo->add_to_world(QualifiedPackageName("cat-one/foofoo"));
+ std::ifstream world("vdb_repository_TEST_dir/world-no-match");
+ std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/bar\ncat-one/oink\ncat-one/foofoo\n");
+ }
+ } test_vdb_repository_add_to_world_no_match;
+
+ /**
+ * \test Test VDBRepository add_to_world.
+ */
+ struct VDBRepositoryAddToWorldMatchTest : TestCase
+ {
+ VDBRepositoryAddToWorldMatchTest() : TestCase("add to world (match)") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "vdb");
+ keys->insert("location", "vdb_repository_TEST_dir/repo1");
+ keys->insert("world", "vdb_repository_TEST_dir/world-match");
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ repo->add_to_world(QualifiedPackageName("cat-one/foofoo"));
+ std::ifstream world("vdb_repository_TEST_dir/world-match");
+ std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/foofoo\ncat-one/bar\n");
+ }
+ } test_vdb_repository_add_to_world_match;
+
+ /**
+ * \test Test VDBRepository add_to_world.
+ */
+ struct VDBRepositoryAddToWorldNoMatchNoEOLTest : TestCase
+ {
+ VDBRepositoryAddToWorldNoMatchNoEOLTest() : TestCase("add to world (no match, no trailing eol)") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "vdb");
+ keys->insert("location", "vdb_repository_TEST_dir/repo1");
+ keys->insert("world", "vdb_repository_TEST_dir/world-no-match-no-eol");
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ repo->add_to_world(QualifiedPackageName("cat-one/foofoo"));
+ std::ifstream world("vdb_repository_TEST_dir/world-no-match-no-eol");
+ std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/bar\ncat-one/oink\ncat-one/foofoo\n");
+ }
+ } test_vdb_repository_add_to_world_no_match_no_eol;
}
diff --git a/paludis/repositories/vdb/vdb_repository_TEST_setup.sh b/paludis/repositories/vdb/vdb_repository_TEST_setup.sh
index e816209..138a6b1 100755
--- a/paludis/repositories/vdb/vdb_repository_TEST_setup.sh
+++ b/paludis/repositories/vdb/vdb_repository_TEST_setup.sh
@@ -15,3 +15,21 @@ for i in DEPEND RDEPEND LICENSE INHERITED IUSE PDEPEND PROVIDE; do
done
echo "flag1 flag2" >>repo1/cat-one/pkg-one-1/USE
+
+touch "world-empty"
+cat <<END > world-no-match
+cat-one/foo
+cat-one/bar
+cat-one/oink
+END
+cat <<END > world-match
+cat-one/foo
+cat-one/foofoo
+cat-one/bar
+END
+cat <<END > world-no-match-no-eol
+cat-one/foo
+cat-one/bar
+END
+echo -n "cat-one/oink" >> world-no-match-no-eol
+