aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-30 20:27:48 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-30 20:27:48 +0000
commitecce91b572d9fec3eaede4b22db51a1ec133aa46 (patch)
tree29d98775802bd5cd013db10b53716096efaed4e6
parent63fc4df43dfd532efad0c704ef73d2e01acc10e7 (diff)
downloadpaludis-ecce91b572d9fec3eaede4b22db51a1ec133aa46.tar.gz
paludis-ecce91b572d9fec3eaede4b22db51a1ec133aa46.tar.xz
Fix mirror:// path handling. Fixes: ticket:332
-rw-r--r--paludis/environments/test/test_environment.cc12
-rw-r--r--paludis/repositories/e/source_uri_finder.cc25
-rw-r--r--paludis/repositories/e/source_uri_finder_TEST.cc48
3 files changed, 69 insertions, 16 deletions
diff --git a/paludis/environments/test/test_environment.cc b/paludis/environments/test/test_environment.cc
index 3e51e15..5763bdb 100644
--- a/paludis/environments/test/test_environment.cc
+++ b/paludis/environments/test/test_environment.cc
@@ -138,9 +138,17 @@ TestEnvironment::root() const
}
tr1::shared_ptr<const MirrorsSequence>
-TestEnvironment::mirrors(const std::string &) const
+TestEnvironment::mirrors(const std::string & s) const
{
- return make_shared_ptr(new MirrorsSequence);
+ tr1::shared_ptr<MirrorsSequence> result(new MirrorsSequence);
+
+ if (s == "example")
+ {
+ result->push_back("http://example-mirror-1/example-mirror-1/");
+ result->push_back("http://example-mirror-2/example-mirror-2/");
+ }
+
+ return result;
}
HookResult
diff --git a/paludis/repositories/e/source_uri_finder.cc b/paludis/repositories/e/source_uri_finder.cc
index 9eb4d51..916ff4e 100644
--- a/paludis/repositories/e/source_uri_finder.cc
+++ b/paludis/repositories/e/source_uri_finder.cc
@@ -21,6 +21,7 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/log.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
#include <paludis/repository.hh>
#include <paludis/environment.hh>
#include <paludis/action.hh>
@@ -133,8 +134,8 @@ SourceURIFinder::add_local_mirrors()
for (MirrorsSequence::Iterator m(mirrors->begin()), m_end(mirrors->end()) ; m != m_end ; ++m)
{
- Log::get_instance()->message(ll_debug, lc_context) << "Adding " << *m << "/" << _imp->filename;
- _imp->items.push_back(std::make_pair(*m + "/" + _imp->filename, _imp->filename));
+ Log::get_instance()->message(ll_debug, lc_context) << "Adding " << strip_trailing(*m, "/") << "/" << _imp->filename;
+ _imp->items.push_back(std::make_pair(strip_trailing(*m, "/") + "/" + _imp->filename, _imp->filename));
}
}
@@ -149,8 +150,8 @@ SourceURIFinder::add_mirrors()
for (MirrorsSequence::Iterator m(mirrors->begin()), m_end(mirrors->end()) ; m != m_end ; ++m)
{
- Log::get_instance()->message(ll_debug, lc_context) << "Adding " << *m << "/" << _imp->filename;
- _imp->items.push_back(std::make_pair(*m + "/" + _imp->filename, _imp->filename));
+ Log::get_instance()->message(ll_debug, lc_context) << "Adding " << strip_trailing(*m, "/") << "/" << _imp->filename;
+ _imp->items.push_back(std::make_pair(strip_trailing(*m, "/") + "/" + _imp->filename, _imp->filename));
}
{
@@ -160,8 +161,8 @@ SourceURIFinder::add_mirrors()
m_end(_imp->repo->mirrors_interface->end_mirrors(_imp->mirrors_name)) ;
m != m_end ; ++m)
{
- Log::get_instance()->message(ll_debug, lc_context) << "Adding " << m->second << "/" << _imp->filename;
- _imp->items.push_back(std::make_pair(m->second + "/" + _imp->filename, _imp->filename));
+ Log::get_instance()->message(ll_debug, lc_context) << "Adding " << strip_trailing(m->second, "/") << "/" << _imp->filename;
+ _imp->items.push_back(std::make_pair(strip_trailing(m->second, "/") + "/" + _imp->filename, _imp->filename));
}
}
}
@@ -177,10 +178,9 @@ SourceURIFinder::add_listed()
std::string::size_type p(mirror.find("/"));
if (std::string::npos == p)
throw FetchActionError("Broken URI component '" + _imp->url + "'");
+ std::string original_name(mirror.substr(p + 1));
mirror.erase(p);
- std::string original_name(_imp->url.substr(_imp->url.rfind("/")));
-
{
Context local_context("When adding from environment for listed mirror '" + mirror + "':");
tr1::shared_ptr<const MirrorsSequence> mirrors(_imp->env->mirrors(mirror));
@@ -188,8 +188,8 @@ SourceURIFinder::add_listed()
Log::get_instance()->message(ll_debug, lc_context) << "Mirrors set is empty";
for (MirrorsSequence::Iterator m(mirrors->begin()), m_end(mirrors->end()) ; m != m_end ; ++m)
{
- Log::get_instance()->message(ll_debug, lc_context) << "Adding " << *m << "/" << original_name;
- _imp->items.push_back(std::make_pair(*m + "/" + original_name, _imp->filename));
+ Log::get_instance()->message(ll_debug, lc_context) << "Adding " << strip_trailing(*m, "/") << "/" << original_name;
+ _imp->items.push_back(std::make_pair(strip_trailing(*m, "/") + "/" + original_name, _imp->filename));
}
}
@@ -200,8 +200,9 @@ SourceURIFinder::add_listed()
m_end(_imp->repo->mirrors_interface->end_mirrors(mirror)) ;
m != m_end ; ++m)
{
- Log::get_instance()->message(ll_debug, lc_context) << "Adding " << m->second << "/" << original_name;
- _imp->items.push_back(std::make_pair(m->second + "/" + original_name, _imp->filename));
+ Log::get_instance()->message(ll_debug, lc_context) << "Adding " << strip_trailing(m->second, "/")
+ << "/" << original_name;
+ _imp->items.push_back(std::make_pair(strip_trailing(m->second, "/") + "/" + original_name, _imp->filename));
}
}
}
diff --git a/paludis/repositories/e/source_uri_finder_TEST.cc b/paludis/repositories/e/source_uri_finder_TEST.cc
index e832978..2f73f00 100644
--- a/paludis/repositories/e/source_uri_finder_TEST.cc
+++ b/paludis/repositories/e/source_uri_finder_TEST.cc
@@ -41,14 +41,14 @@ namespace test_cases
const tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
env.package_database()->add_repository(1, repo);
- SourceURIFinder f(&env, repo.get(), "http://example.com/input", "output", "monkey");
+ SourceURIFinder f(&env, repo.get(), "http://example.com/path/input", "output", "monkey");
URIMirrorsThenListedLabel label("mirrors-then-listed");
label.accept(f);
SourceURIFinder::Iterator i(f.begin());
TEST_CHECK(i != f.end());
- TEST_CHECK_EQUAL(i->first, "http://example.com/input");
+ TEST_CHECK_EQUAL(i->first, "http://example.com/path/input");
TEST_CHECK_EQUAL(i->second, "output");
++i;
@@ -56,5 +56,49 @@ namespace test_cases
TEST_CHECK(i == f.end());
}
} test_source_uri_finder;
+
+ struct SourceURIMirrorFinderTest : TestCase
+ {
+ SourceURIMirrorFinderTest() : TestCase("source uri mirror finder") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ const tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+
+ SourceURIFinder f(&env, repo.get(), "mirror://example/path/input", "output", "repo");
+ URIMirrorsThenListedLabel label("mirrors-then-listed");
+ label.accept(f);
+
+ SourceURIFinder::Iterator i(f.begin());
+
+ TEST_CHECK(i != f.end());
+ TEST_CHECK_EQUAL(i->first, "http://fake-repo/fake-repo/output");
+ TEST_CHECK_EQUAL(i->second, "output");
+
+ ++i;
+
+ TEST_CHECK(i != f.end());
+ TEST_CHECK_EQUAL(i->first, "http://example-mirror-1/example-mirror-1/path/input");
+ TEST_CHECK_EQUAL(i->second, "output");
+
+ ++i;
+
+ TEST_CHECK(i != f.end());
+ TEST_CHECK_EQUAL(i->first, "http://example-mirror-2/example-mirror-2/path/input");
+ TEST_CHECK_EQUAL(i->second, "output");
+
+ ++i;
+
+ TEST_CHECK(i != f.end());
+ TEST_CHECK_EQUAL(i->first, "http://fake-example/fake-example/path/input");
+ TEST_CHECK_EQUAL(i->second, "output");
+
+ ++i;
+
+ TEST_CHECK(i == f.end());
+ }
+ } test_source_uri_mirror_finder;
}