aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-19 18:19:29 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-19 18:19:29 +0000
commitb3966cea888c1bff7a945cb86c7c886c8a7174fa (patch)
treef45796b01d77aeec20b8a92c11366828260216f3
parent598b07fdff1a361502c9e001cbc3eef2b26e13e4 (diff)
downloadpaludis-b3966cea888c1bff7a945cb86c7c886c8a7174fa.tar.gz
paludis-b3966cea888c1bff7a945cb86c7c886c8a7174fa.tar.xz
Restore categories check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am4
-rw-r--r--paludis/repositories/e/qa/categories.cc102
-rw-r--r--paludis/repositories/e/qa/categories.hh38
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc4
4 files changed, 147 insertions, 1 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 91392a5..7505c0e 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -50,7 +50,8 @@ paludis_repositories_e_include_HEADERS = \
ebuild_count.hh \
misc_files.hh \
files_dir_size.hh \
- repo_name.hh
+ repo_name.hh \
+ categories.hh
lib_LTLIBRARIES = libpaludiserepositoryqa.la
@@ -79,6 +80,7 @@ libpaludiserepositoryqa_la_SOURCES = \
misc_files.cc \
files_dir_size.cc \
repo_name.cc \
+ categories.cc \
$(paludis_repositories_e_include_HEADERS)
libpaludiserepositoryqa_la_LDFLAGS = \
diff --git a/paludis/repositories/e/qa/categories.cc b/paludis/repositories/e/qa/categories.cc
new file mode 100644
index 0000000..908aaa2
--- /dev/null
+++ b/paludis/repositories/e/qa/categories.cc
@@ -0,0 +1,102 @@
+/* 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 "categories.hh"
+#include <paludis/qa.hh>
+#include <paludis/repositories/e/e_repository.hh>
+#include <paludis/repositories/e/layout.hh>
+#include <paludis/util/config_file.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/options.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+
+#include <set>
+
+using namespace paludis;
+
+bool
+paludis::erepository::categories_check(
+ QAReporter & reporter,
+ const tr1::shared_ptr<const ERepository> & repo,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "':");
+ FSEntry cats(repo->layout()->categories_file());
+ Log::get_instance()->message(ll_debug, lc_context) << "categories_check '"
+ << cats << "', " << name << "'";
+
+ try
+ {
+ if (! cats.is_regular_file_or_symlink_to_regular_file())
+ {
+ if (cats.exists() || ! repo->params().master_repository)
+ reporter.message(QAMessage(cats, qaml_severe, name, "Categories file is not a regular file"));
+ }
+ else
+ {
+ LineConfigFile cf(cats, LineConfigFileOptions());
+ std::set<CategoryNamePart> c;
+
+ for (LineConfigFile::ConstIterator line(cf.begin()), line_end(cf.end()) ;
+ line != line_end ; ++line)
+ {
+ try
+ {
+ CategoryNamePart n(*line);
+ std::pair<std::set<CategoryNamePart>::const_iterator, bool> r(c.insert(n));
+
+ if (! r.second)
+ reporter.message(QAMessage(cats, qaml_normal, name, "Categories file entry '"
+ + stringify(*line) + "' is not unique"));
+ else if (next(r.first) != c.end())
+ reporter.message(QAMessage(cats, qaml_minor, name, "Categories file entry '"
+ + stringify(*line) + "' is not in order"));
+ else
+ {
+ FSEntry f(repo->layout()->category_directory(n));
+
+ if (! f.is_directory_or_symlink_to_directory())
+ {
+ if (f.exists())
+ reporter.message(QAMessage(cats, qaml_normal, name, "Categories file entry '"
+ + stringify(*line) + "' exists but is not a directory"));
+ else
+ reporter.message(QAMessage(cats, qaml_minor, name, "Categories file entry '"
+ + stringify(*line) + "' does not exist"));
+ }
+ }
+ }
+ catch (const NameError &)
+ {
+ reporter.message(QAMessage(cats, qaml_severe, name, "Categories file entry '"
+ + stringify(*line) + "' is not a valid category name"));
+ }
+ }
+ }
+ }
+ catch (const Exception & err)
+ {
+ reporter.message(QAMessage(cats, qaml_severe, name, "Caught Exception '" + err.message() + "' ("
+ + err.what() + ") when handling categories file"));
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/categories.hh b/paludis/repositories/e/qa/categories.hh
new file mode 100644
index 0000000..24cf81a
--- /dev/null
+++ b/paludis/repositories/e/qa/categories.hh
@@ -0,0 +1,38 @@
+/* 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_CATEGORIES_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_CATEGORIES_HH 1
+
+#include <paludis/repositories/e/qa/qa_controller.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool categories_check(
+ QAReporter &,
+ const tr1::shared_ptr<const ERepository> &,
+ const std::string &
+ );
+ }
+}
+
+
+#endif
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index f7ccce1..e6d59b9 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -41,6 +41,7 @@
#include <paludis/repositories/e/qa/whitespace.hh>
#include <paludis/repositories/e/qa/header.hh>
#include <paludis/repositories/e/qa/repo_name.hh>
+#include <paludis/repositories/e/qa/categories.hh>
using namespace paludis;
using namespace paludis::erepository;
@@ -82,6 +83,9 @@ QAChecks::QAChecks() :
_imp->tree_checks_group->add_check("repo_name",
tr1::bind(repo_name_check, _2, _1, "repo_name"));
+ _imp->tree_checks_group->add_check("categories",
+ tr1::bind(categories_check, _2, _4, "categories"));
+
_imp->eclass_file_contents_checks_group->add_check("variable_assigns",
tr1::bind(variable_assigns_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "variable_assigns"));