aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-23 18:58:46 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-23 18:58:46 +0000
commitede5cbb9532eeec7b0b859007c22e49351b291c8 (patch)
tree3fd12cb8260da74512378556fcc3a392d99b680b
parent9153ce0d312772820bbc0838e017a48c48c9a3a6 (diff)
downloadpaludis-ede5cbb9532eeec7b0b859007c22e49351b291c8.tar.gz
paludis-ede5cbb9532eeec7b0b859007c22e49351b291c8.tar.xz
Add fetches_key check, equivalant to the old src_uri_check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/fetches_key.cc217
-rw-r--r--paludis/repositories/e/qa/fetches_key.hh39
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc5
4 files changed, 263 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 2725fc2..48eb613 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -31,6 +31,7 @@ paludis_repositories_e_include_HEADERS = \
eapi_supported.hh \
metadata_keys.hh \
extractors.hh \
+ fetches_key.hh \
homepage_key.hh \
iuse_key.hh \
spec_keys.hh \
@@ -63,6 +64,7 @@ libpaludiserepositoryqa_la_SOURCES = \
eapi_supported.cc \
metadata_keys.cc \
extractors.cc \
+ fetches_key.cc \
homepage_key.cc \
iuse_key.cc \
qa_checks.cc \
diff --git a/paludis/repositories/e/qa/fetches_key.cc b/paludis/repositories/e/qa/fetches_key.cc
new file mode 100644
index 0000000..59659a8
--- /dev/null
+++ b/paludis/repositories/e/qa/fetches_key.cc
@@ -0,0 +1,217 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006, 2007 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 "fetches_key.hh"
+#include <paludis/qa.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/save.hh>
+#include <paludis/name.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/dep_label.hh>
+#include <paludis/package_id.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/fs_entry.hh>
+
+using namespace paludis;
+
+namespace
+{
+ struct LabelToFetchRestrict : ConstVisitor<URILabelVisitorTypes>
+ {
+ bool value;
+
+ LabelToFetchRestrict(const URILabel & l)
+ {
+ l.accept(*this);
+ }
+
+ void visit(const URIMirrorsThenListedLabel &)
+ {
+ value = false;
+ }
+
+ void visit(const URIMirrorsOnlyLabel &)
+ {
+ value = true;
+ }
+
+ void visit(const URIListedOnlyLabel &)
+ {
+ value = false;
+ }
+
+ void visit(const URIListedThenMirrorsLabel &)
+ {
+ value = false;
+ }
+
+ void visit(const URILocalMirrorsOnlyLabel &)
+ {
+ value = true;
+ }
+
+ void visit(const URIManualOnlyLabel &)
+ {
+ value = true;
+ }
+ };
+
+ struct Checker : ConstVisitor<FetchableURISpecTree>
+ {
+ QAReporter & reporter;
+ bool fetch_restrict;
+ tr1::shared_ptr<const PackageID> id;
+ tr1::shared_ptr<const MetadataKey> key;
+ FSEntry entry;
+ std::string name;
+
+ Checker(QAReporter & rr, bool f,
+ const tr1::shared_ptr<const PackageID> & i,
+ const tr1::shared_ptr<const MetadataKey> & k,
+ const FSEntry & fs, const std::string & n) :
+ reporter(rr),
+ fetch_restrict(f),
+ id(i),
+ key(k),
+ entry(fs),
+ name(n)
+ {
+ }
+
+ void visit_leaf(const FetchableURIDepSpec & a)
+ {
+ std::string::size_type p(std::string::npos);
+ if (std::string::npos == ((p = a.original_url().find("://"))) && ! fetch_restrict)
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "No protocol found for '" + a.original_url() +
+ "' and not fetch restricted in '" + key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+
+ else if ((std::string::npos != p) &&
+ (("http" != a.original_url().substr(0, p)) &&
+ ("https" != a.original_url().substr(0, p)) &&
+ ("mirror" != a.original_url().substr(0, p)) &&
+ ("ftp" != a.original_url().substr(0, p))))
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "Unrecognised protocol for '" + a.original_url() +
+ "' in '" + key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+
+ else if ((std::string::npos != a.original_url().find("dev.gentoo.org")) ||
+ (std::string::npos != a.original_url().find("cvs.gentoo.org")) ||
+ (std::string::npos != a.original_url().find("toucan.gentoo.org")) ||
+ (std::string::npos != a.original_url().find("emu.gentoo.org")) ||
+ (std::string::npos != a.original_url().find("alpha.gnu.org")) ||
+ (std::string::npos != a.original_url().find("geocities.com")))
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "Unreliable host for '" + a.original_url() + "' in '" +
+ key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+
+ else
+ {
+ if (0 == a.original_url().compare(0, 9, "mirror://"))
+ {
+ std::string mirror_host(a.original_url().substr(9));
+ std::string::size_type pos(mirror_host.find('/'));
+ if (std::string::npos == pos)
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "Malformed component '" + a.original_url() + "' in '" +
+ key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+ else
+ {
+ mirror_host.erase(pos);
+ RepositoryMirrorsInterface * m(id->repository()->mirrors_interface);
+ if (! m->is_mirror(mirror_host))
+ reporter.message(QAMessage(entry, qaml_normal, name,
+ "Unknown mirror '" + mirror_host + "' for '" +
+ a.original_url() + "' in '" + key->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, key));
+ }
+ }
+ }
+ }
+
+ void visit_leaf(const URILabelsDepSpec & a)
+ {
+ if (1 != std::distance(a.begin(), a.end()))
+ throw InternalError(PALUDIS_HERE, "URILabelsDepSpec contains " +
+ stringify(std::distance(a.begin(), a.end())) + " labels, but expected 1");
+ fetch_restrict = LabelToFetchRestrict(**a.begin()).value;
+ }
+
+ void visit_sequence(const AllDepSpec &,
+ FetchableURISpecTree::ConstSequenceIterator begin,
+ FetchableURISpecTree::ConstSequenceIterator end)
+ {
+ Save<bool> s(&fetch_restrict);
+ std::for_each(begin, end, accept_visitor(*this));
+ }
+
+ void visit_sequence(const UseDepSpec &,
+ FetchableURISpecTree::ConstSequenceIterator begin,
+ FetchableURISpecTree::ConstSequenceIterator end)
+ {
+ Save<bool> s(&fetch_restrict);
+ std::for_each(begin, end, accept_visitor(*this));
+ }
+ };
+}
+
+bool
+paludis::erepository::fetches_key_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const PackageID> & id,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' using fetches_key_check on ID '" + stringify(*id) + "':");
+ Log::get_instance()->message(ll_debug, lc_context) << "fetches_key_check '"
+ << entry << "', " << *id << "', " << name << "'";
+
+ try
+ {
+ if (id->fetches_key())
+ {
+ Checker c(reporter, LabelToFetchRestrict(*id->fetches_key()->initial_label()).value,
+ id, id->fetches_key(), entry, name);
+ id->fetches_key()->value()->accept(c);
+ }
+ }
+ catch (const Exception & e)
+ {
+ reporter.message(QAMessage(entry, qaml_severe, name,
+ "Caught exception '" + stringify(e.message()) + "' ("
+ + stringify(e.what()) + ") when handling key '" + id->fetches_key()->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(id, id->fetches_key()));
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/fetches_key.hh b/paludis/repositories/e/qa/fetches_key.hh
new file mode 100644
index 0000000..aa3c83a
--- /dev/null
+++ b/paludis/repositories/e/qa/fetches_key.hh
@@ -0,0 +1,39 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_FETCHES_KEY_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_FETCHES_KEY_HH 1
+
+#include <paludis/qa-fwd.hh>
+#include <paludis/repositories/e/e_repository_id.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool fetches_key_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &);
+ }
+}
+
+#endif
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index f0d66ec..9359915 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -34,6 +34,7 @@
#include <paludis/repositories/e/qa/iuse_key.hh>
#include <paludis/repositories/e/qa/spec_keys.hh>
#include <paludis/repositories/e/qa/extractors.hh>
+#include <paludis/repositories/e/qa/fetches_key.hh>
#include <paludis/repositories/e/qa/restrict_key.hh>
#include <paludis/repositories/e/qa/visibility.hh>
#include <paludis/repositories/e/qa/default_functions.hh>
@@ -146,6 +147,10 @@ QAChecks::QAChecks() :
tr1::bind(extractors_check, _1, _2, _5, "extractors"));
_imp->package_id_checks_group->add_prerequirement("extractors", "metadata_keys");
+ _imp->package_id_checks_group->add_check("fetches_key",
+ tr1::bind(fetches_key_check, _1, _2, _5, "fetches_key"));
+ _imp->package_id_checks_group->add_prerequirement("fetches_key", "metadata_keys");
+
_imp->package_id_checks_group->add_check("restrict_key",
tr1::bind(restrict_key_check, _1, _2, _5, "restrict_key"));
_imp->package_id_checks_group->add_prerequirement("restrict_key", "metadata_keys");