aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-31 01:13:12 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-31 01:13:12 +0000
commitfd054108ccc5edafe102ef201dc73539af8435a3 (patch)
treeb1e331debf0b613afe6f0c32f405d9e5c80cdf99
parent6795102af57ee056a2c7c262f4409640ad2f464f (diff)
downloadpaludis-fd054108ccc5edafe102ef201dc73539af8435a3.tar.gz
paludis-fd054108ccc5edafe102ef201dc73539af8435a3.tar.xz
Check profiles/categories correctness
-rw-r--r--paludis/qa/categories_check.cc90
-rw-r--r--paludis/qa/categories_check.hh53
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/profiles_check.cc2
4 files changed, 146 insertions, 0 deletions
diff --git a/paludis/qa/categories_check.cc b/paludis/qa/categories_check.cc
new file mode 100644
index 0000000..8200bcf
--- /dev/null
+++ b/paludis/qa/categories_check.cc
@@ -0,0 +1,90 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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 <paludis/qa/categories_check.hh>
+#include <paludis/qa/qa_environment.hh>
+#include <paludis/config_file.hh>
+
+#include <set>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+CategoriesCheck::CategoriesCheck()
+{
+}
+
+CheckResult
+CategoriesCheck::operator() (const FSEntry & d) const
+{
+ CheckResult result(stringify(d), identifier());
+
+ try
+ {
+ FSEntry cats(d / "categories");
+ if (! cats.is_regular_file())
+ result << Message(qal_fatal, "Categories file '" + stringify(cats) + "' is not a regular file");
+ else
+ {
+ LineConfigFile cf(cats);
+ std::set<CategoryNamePart> c;
+
+ for (LineConfigFile::Iterator 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)
+ result << Message(qal_major, "Categories file '" + stringify(cats) + "' entry '"
+ + stringify(*line) + "' is not unique");
+ else if (next(r.first) != c.end())
+ result << Message(qal_minor, "Categories file '" + stringify(cats) + "' entry '"
+ + stringify(*line) + "' is not in order");
+ }
+ catch (const NameError &)
+ {
+ result << Message(qal_fatal, "Categories file '" + stringify(cats) + "' entry '"
+ + stringify(*line) + "' is not a valid category name");
+ }
+ }
+ }
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & err)
+ {
+ result << Message(qal_fatal, "Caught Exception '" + err.message() + "' ("
+ + err.what() + ")");
+ }
+
+ return result;
+}
+
+const std::string &
+CategoriesCheck::identifier()
+{
+ static const std::string id("categories");
+ return id;
+}
+
+
diff --git a/paludis/qa/categories_check.hh b/paludis/qa/categories_check.hh
new file mode 100644
index 0000000..d624223
--- /dev/null
+++ b/paludis/qa/categories_check.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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_CATEGORIES_HH
+#define PALUDIS_GUARD_PALUDIS_QA_CATEGORIES_HH 1
+
+#include <paludis/qa/profiles_check.hh>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: profiles/categories.
+ *
+ * \ingroup grpqa
+ */
+ class CategoriesCheck :
+ public ProfilesCheck
+ {
+ public:
+ CategoriesCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks that categories is sane";
+ }
+ };
+
+ }
+}
+
+#endif
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 9b4e897..be6140d 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -8,6 +8,7 @@ dnl the base filename with no extension; later parameters can be `hh', `cc',
dnl `test', `impl', `testscript'. Note that there isn't much error checking done
dnl on this file at present...
+add(`categories_check', `hh', `cc')
add(`changelog_check', `hh', `cc')
add(`check', `hh', `cc')
add(`check_result', `hh', `cc', `test')
diff --git a/paludis/qa/profiles_check.cc b/paludis/qa/profiles_check.cc
index 89511fa..7032ffb 100644
--- a/paludis/qa/profiles_check.cc
+++ b/paludis/qa/profiles_check.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/qa/profiles_check.hh>
+#include <paludis/qa/categories_check.hh>
using namespace paludis;
using namespace paludis::qa;
@@ -33,6 +34,7 @@ NoSuchProfilesCheckTypeError::NoSuchProfilesCheckTypeError(const std::string & s
ProfilesCheckMaker::ProfilesCheckMaker()
{
+ register_maker(CategoriesCheck::identifier(), &MakeProfilesCheck<CategoriesCheck>::make_profiles_check);
}