aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 16:19:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-18 16:19:39 +0000
commit0c85faac7c8c10c4f540e621eab8a4a35ac69b1d (patch)
tree6a19598270ec85659df264e1ff88b05049715a9d
parent7ed1d218e0595a66b7142c7901a223f75b072f62 (diff)
downloadpaludis-0c85faac7c8c10c4f540e621eab8a4a35ac69b1d.tar.gz
paludis-0c85faac7c8c10c4f540e621eab8a4a35ac69b1d.tar.xz
Check RESTRICT
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/restrict_check.cc95
-rw-r--r--paludis/qa/restrict_check.hh51
3 files changed, 147 insertions, 0 deletions
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index e231003..b1d1094 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -37,6 +37,7 @@ add(`package_dir_check', `hh', `cc')
add(`package_name_check', `hh', `cc', `test', `testscript')
add(`parse_deps_check', `hh', `cc')
add(`rdepend_packages_check', `hh', `cc')
+add(`restrict_check', `hh', `cc')
add(`src_uri_check', `hh', `cc')
add(`pdepend_overlap_check', `hh', `cc')
add(`qa', `hh', `cc')
diff --git a/paludis/qa/restrict_check.cc b/paludis/qa/restrict_check.cc
new file mode 100644
index 0000000..2015cb8
--- /dev/null
+++ b/paludis/qa/restrict_check.cc
@@ -0,0 +1,95 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 "restrict_check.hh"
+#include <paludis/tokeniser.hh>
+#include <algorithm>
+#include <set>
+#include <iterator>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+RestrictCheck::RestrictCheck()
+{
+}
+
+CheckResult
+RestrictCheck::operator() (const EbuildCheckData & e) const
+{
+ CheckResult result(stringify(e.get<ecd_name>()) + "-" + stringify(e.get<ecd_version>()),
+ identifier());
+
+ try
+ {
+ PackageDatabaseEntry ee(e.get<ecd_name>(), e.get<ecd_version>(),
+ e.get<ecd_environment>()->package_database()->favourite_repository());
+ VersionMetadata::ConstPointer metadata(
+ e.get<ecd_environment>()->package_database()->fetch_metadata(ee));
+
+ std::set<std::string> restricts;
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
+ tokeniser.tokenise(metadata->get(vmk_restrict),
+ std::inserter(restricts, restricts.begin()));
+
+ static std::set<std::string> allowed_restricts;
+ if (allowed_restricts.empty())
+ {
+ allowed_restricts.insert("fetch");
+ allowed_restricts.insert("mirror");
+ allowed_restricts.insert("nomirror");
+ allowed_restricts.insert("primaryuri");
+ allowed_restricts.insert("strip");
+ allowed_restricts.insert("sandbox");
+ allowed_restricts.insert("userpriv");
+ allowed_restricts.insert("test");
+ }
+
+ std::set<std::string> unknown;
+ std::set_difference(restricts.begin(), restricts.end(),
+ allowed_restricts.begin(), allowed_restricts.end(),
+ std::inserter(unknown, unknown.begin()));
+
+ if (! unknown.empty())
+ result << Message(qal_major, "Unrecognised RESTRICT values '"
+ + join(unknown.begin(), unknown.end(), "', '") + "'");
+
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & e)
+ {
+ result << Message(qal_fatal, "Caught Exception '" + e.message() + "' ("
+ + e.what() + ")");
+ }
+
+ return result;
+}
+
+const std::string &
+RestrictCheck::identifier()
+{
+ static const std::string id("restrict");
+ return id;
+}
+
+
+
diff --git a/paludis/qa/restrict_check.hh b/paludis/qa/restrict_check.hh
new file mode 100644
index 0000000..4dd0741
--- /dev/null
+++ b/paludis/qa/restrict_check.hh
@@ -0,0 +1,51 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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_QA_RESTRICT_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_RESTRICT_CHECK_HH 1
+
+#include <paludis/qa/ebuild_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class RestrictCheck :
+ public EbuildCheck
+ {
+ public:
+ RestrictCheck();
+
+ CheckResult operator() (const EbuildCheckData &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks that RESTRICT is sane";
+ }
+ };
+
+ static const EbuildCheckMaker::RegisterMaker register_restrict_check(
+ RestrictCheck::identifier(), &MakeEbuildCheck<RestrictCheck>::make_ebuild_check);
+ }
+}
+
+#endif