aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-07 03:09:58 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-07 03:09:58 +0000
commit261d35f90f9680f5b3af418400957906ccfe498d (patch)
tree15fb433c1619cb489a027105e044a545f66f7172
parentf33acc94ef72bb4c0aebf79fe4393d4aa308f686 (diff)
downloadpaludis-261d35f90f9680f5b3af418400957906ccfe498d.tar.gz
paludis-261d35f90f9680f5b3af418400957906ccfe498d.tar.xz
Cope better with malformed metadata keys.
-rw-r--r--paludis/repositories/e/qa/Makefile.am2
-rw-r--r--paludis/repositories/e/qa/metadata_keys.cc176
-rw-r--r--paludis/repositories/e/qa/metadata_keys.hh41
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc14
-rw-r--r--src/clients/qualudis/qualudis.cc14
5 files changed, 240 insertions, 7 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 1095e6b..bf6616b 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -28,6 +28,7 @@ dist_paludis_qa_data_DATA = \
paludis_repositories_e_includedir = $(includedir)/paludis-$(PALUDIS_PC_SLOT)/paludis/repositories/e/
paludis_repositories_e_include_HEADERS = \
eapi_supported.hh \
+ metadata_keys.hh \
extractors.hh \
homepage_key.hh \
spec_keys.hh \
@@ -46,6 +47,7 @@ lib_LTLIBRARIES = libpaludiserepositoryqa.la
libpaludiserepositoryqa_la_SOURCES = \
qa.cc \
eapi_supported.cc \
+ metadata_keys.cc \
extractors.cc \
homepage_key.cc \
qa_checks.cc \
diff --git a/paludis/repositories/e/qa/metadata_keys.cc b/paludis/repositories/e/qa/metadata_keys.cc
new file mode 100644
index 0000000..803b45c
--- /dev/null
+++ b/paludis/repositories/e/qa/metadata_keys.cc
@@ -0,0 +1,176 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2008 David Leverton
+ *
+ * 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 "metadata_keys.hh"
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/qa.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/set.hh>
+
+using namespace paludis;
+using namespace paludis::erepository;
+
+namespace
+{
+ struct KeyValidator :
+ ConstVisitor<MetadataKeyVisitorTypes>
+ {
+ void visit(const MetadataStringKey & k)
+ {
+ const std::string & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataSizeKey & k)
+ {
+ long PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataPackageIDKey & k)
+ {
+ const tr1::shared_ptr<const PackageID> & PALUDIS_ATTRIBUTE((unused)) p(k.value());
+ }
+
+ void visit(const MetadataTimeKey & k)
+ {
+ time_t PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataContentsKey & k)
+ {
+ const tr1::shared_ptr<const Contents> & PALUDIS_ATTRIBUTE((unused)) c(k.value());
+ }
+
+ void visit(const MetadataFSEntryKey & k)
+ {
+ const FSEntry & PALUDIS_ATTRIBUTE((unused)) c(k.value());
+ }
+
+ void visit(const MetadataRepositoryMaskInfoKey & k)
+ {
+ const tr1::shared_ptr<const RepositoryMaskInfo> & PALUDIS_ATTRIBUTE((unused)) i(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<RestrictSpecTree> & k)
+ {
+ const tr1::shared_ptr<RestrictSpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
+ {
+ const tr1::shared_ptr<ProvideSpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k)
+ {
+ const tr1::shared_ptr<FetchableURISpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k)
+ {
+ const tr1::shared_ptr<SimpleURISpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
+ {
+ const tr1::shared_ptr<LicenseSpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
+ {
+ const tr1::shared_ptr<DependencySpecTree::ConstItem> & PALUDIS_ATTRIBUTE((unused)) t(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<PackageIDSequence> & k)
+ {
+ const tr1::shared_ptr<const PackageIDSequence> & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<Set<std::string> > & k)
+ {
+ const tr1::shared_ptr<const Set<std::string> > & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<FSEntrySequence> & k)
+ {
+ const tr1::shared_ptr<const FSEntrySequence> & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<KeywordNameSet> & k)
+ {
+ const tr1::shared_ptr<const KeywordNameSet> & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<IUseFlagSet> & k)
+ {
+ const tr1::shared_ptr<const IUseFlagSet> & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataCollectionKey<UseFlagNameSet> & k)
+ {
+ const tr1::shared_ptr<const UseFlagNameSet> & PALUDIS_ATTRIBUTE((unused)) s(k.value());
+ }
+
+ void visit(const MetadataSectionKey & k)
+ {
+ std::for_each(indirect_iterator(k.begin_metadata()),
+ indirect_iterator(k.end_metadata()), accept_visitor(*this));
+ }
+ };
+}
+
+bool
+paludis::erepository::metadata_keys_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const PackageID> & id,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' on ID '" + stringify(*id) + "':");
+ Log::get_instance()->message(ll_debug, lc_context) << "extractors_check '"
+ << entry << "', " << *id << "', " << name << "'";
+
+ bool retval(true);
+ KeyValidator validator;
+
+ for (PackageID::MetadataConstIterator it(id->begin_metadata()),
+ it_end(id->end_metadata()); it_end != it; ++it)
+ {
+ try
+ {
+ (*it)->accept(validator);
+ }
+ catch (const Exception & e)
+ {
+ retval = false;
+ reporter.message(QAMessage(entry, qaml_severe, name,
+ "Caught exception '" + stringify(e.message()) + "' ("
+ + stringify(e.what()) + ") when handling key '" + (*it)->raw_name() + "'")
+ .with_associated_id(id)
+ .with_associated_key(*it));
+ }
+ }
+
+ return retval;
+}
+
diff --git a/paludis/repositories/e/qa/metadata_keys.hh b/paludis/repositories/e/qa/metadata_keys.hh
new file mode 100644
index 0000000..1291dd3
--- /dev/null
+++ b/paludis/repositories/e/qa/metadata_keys.hh
@@ -0,0 +1,41 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2008 David Leverton
+ *
+ * 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_PALUDIS_REPOSITORIES_E_QA_METADATA_KEYS_HH
+#define PALUDIS_GUARD_PALUDIS_PALUDIS_REPOSITORIES_E_QA_METADATA_KEYS_HH 1
+
+#include <paludis/qa-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool metadata_keys_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &) PALUDIS_VISIBLE;
+ }
+}
+
+#endif
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index 1ce31ec..48e5e30 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -23,6 +23,7 @@
#include <paludis/repositories/e/qa/stray_files.hh>
#include <paludis/repositories/e/qa/eapi_supported.hh>
+#include <paludis/repositories/e/qa/metadata_keys.hh>
#include <paludis/repositories/e/qa/short_description_key.hh>
#include <paludis/repositories/e/qa/homepage_key.hh>
#include <paludis/repositories/e/qa/spec_keys.hh>
@@ -74,24 +75,29 @@ QAChecks::QAChecks() :
_imp->package_id_checks_group->add_check("eapi_supported",
tr1::bind(eapi_supported_check, _1, _2, _5, "eapi_supported"));
+ _imp->package_id_checks_group->add_check("metadata_keys",
+ tr1::bind(metadata_keys_check, _1, _2, _5, "metadata_keys"));
+ _imp->package_id_checks_group->add_prerequirement("metadata_keys", "eapi_supported");
+
_imp->package_id_checks_group->add_check("short_description_key",
tr1::bind(short_description_key_check, _1, _2, _5, "short_description_key"));
- _imp->package_id_checks_group->add_prerequirement("short_description_key", "eapi_supported");
+ _imp->package_id_checks_group->add_prerequirement("short_description_key", "metadata_keys");
_imp->package_id_checks_group->add_check("homepage_key",
tr1::bind(homepage_key_check, _1, _2, _5, "homepage_key"));
- _imp->package_id_checks_group->add_prerequirement("homepage_key", "eapi_supported");
+ _imp->package_id_checks_group->add_prerequirement("homepage_key", "metadata_keys");
_imp->package_id_checks_group->add_check("spec_keys",
tr1::bind(spec_keys_check, _1, _2, _5, "spec_keys"));
- _imp->package_id_checks_group->add_prerequirement("spec_keys", "eapi_supported");
+ _imp->package_id_checks_group->add_prerequirement("spec_keys", "metadata_keys");
_imp->package_id_checks_group->add_check("extractors",
tr1::bind(extractors_check, _1, _2, _5, "extractors"));
- _imp->package_id_checks_group->add_prerequirement("extractors", "eapi_supported");
+ _imp->package_id_checks_group->add_prerequirement("extractors", "metadata_keys");
_imp->package_id_checks_group->add_check("visibility",
tr1::bind(visibility_check, _1, _2, _3, _4, _5, "visibility"));
+ _imp->package_id_checks_group->add_prerequirement("visibility", "metadata_keys");
_imp->package_id_file_contents_checks_group->add_check("kv_variables",
tr1::bind(kv_variables_check, _1, _2, _5, _6, "kv_variables"));
diff --git a/src/clients/qualudis/qualudis.cc b/src/clients/qualudis/qualudis.cc
index 131f7ec..5f6f34b 100644
--- a/src/clients/qualudis/qualudis.cc
+++ b/src/clients/qualudis/qualudis.cc
@@ -248,9 +248,17 @@ namespace
printed_keys.insert(&**i);
}
- MetadataKeyPrettyPrinter pp;
- (*i)->accept(pp);
- std::cout << " " << pp.stream.str();
+ try
+ {
+ MetadataKeyPrettyPrinter pp;
+ (*i)->accept(pp);
+ std::cout << " " << pp.stream.str();
+ }
+ catch (const Exception &)
+ {
+ // assume one of the QA checks already
+ // printed a suitable error
+ }
}
}
}