aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-23 23:17:49 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-23 23:17:49 +0000
commit89fa5d16f3ae0b167c86c0bde981d6c62b92ae54 (patch)
treeb669db18284066ad079afa0127081caf5b8ff3ae
parent233f70a50ac32a4e82a5770cd5089425c64c4c2c (diff)
downloadpaludis-89fa5d16f3ae0b167c86c0bde981d6c62b92ae54.tar.gz
paludis-89fa5d16f3ae0b167c86c0bde981d6c62b92ae54.tar.xz
Check for digest overlaps
-rw-r--r--paludis/qa/digest_collisions_check.cc103
-rw-r--r--paludis/qa/digest_collisions_check.hh51
-rw-r--r--paludis/qa/files.m41
3 files changed, 155 insertions, 0 deletions
diff --git a/paludis/qa/digest_collisions_check.cc b/paludis/qa/digest_collisions_check.cc
new file mode 100644
index 0000000..a0640cb
--- /dev/null
+++ b/paludis/qa/digest_collisions_check.cc
@@ -0,0 +1,103 @@
+/* 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 "digest_collisions_check.hh"
+#include <paludis/is_file_with_extension.hh>
+#include <paludis/dir_iterator.hh>
+#include <paludis/smart_record.hh>
+#include <paludis/tokeniser.hh>
+#include <map>
+#include <fstream>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+namespace
+{
+ enum DigestDataKeys
+ {
+ de_md5,
+ de_owner
+ };
+
+ struct DigestDataTag :
+ SmartRecordTag<comparison_mode::NoComparisonTag, void>,
+ SmartRecordKeys<DigestDataKeys, 2>,
+ SmartRecordKey<de_md5, std::string>,
+ SmartRecordKey<de_owner, FSEntry>
+ {
+ };
+
+ typedef MakeSmartRecord<DigestDataTag>::Type DigestData;
+
+ static std::map<std::string, DigestData> digests;
+}
+
+DigestCollisionsCheck::DigestCollisionsCheck()
+{
+}
+
+CheckResult
+DigestCollisionsCheck::operator() (const FSEntry & d) const
+{
+ CheckResult result(d, identifier());
+
+ for (DirIterator i(d / "files") ; i != DirIterator() ; ++i)
+ {
+ if (! IsFileWithExtension("digest-", "")(*i))
+ continue;
+
+ std::fstream f(stringify(*i).c_str());
+ std::string line;
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
+ while (std::getline(f, line))
+ {
+ std::vector<std::string> entries;
+ tokeniser.tokenise(line, std::back_inserter(entries));
+
+ if (entries.size() != 4)
+ continue;
+
+ if ("MD5" != entries.at(0))
+ continue;
+
+ std::map<std::string, DigestData>::iterator existing(
+ digests.find(entries.at(2)));
+ if (digests.end() != existing)
+ {
+ if (entries.at(1) != existing->second.get<de_md5>())
+ result << Message(qal_major, "Digest conflict on '" + entries.at(2) +
+ "' (original was '" + stringify(existing->second.get<de_owner>()) + "')");
+ }
+ else
+ digests.insert(std::make_pair(entries.at(2), DigestData(entries.at(1), *i)));
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+DigestCollisionsCheck::identifier()
+{
+ static const std::string id("digest collisions");
+ return id;
+}
+
+
diff --git a/paludis/qa/digest_collisions_check.hh b/paludis/qa/digest_collisions_check.hh
new file mode 100644
index 0000000..5aea864
--- /dev/null
+++ b/paludis/qa/digest_collisions_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_DIGEST_COLLISIONS_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_DIGEST_COLLISIONS_CHECK_HH 1
+
+#include <paludis/qa/package_dir_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class DigestCollisionsCheck :
+ public PackageDirCheck
+ {
+ public:
+ DigestCollisionsCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks for digest collisions";
+ }
+ };
+
+ static const PackageDirCheckMaker::RegisterMaker register_digest_collisions_check(
+ DigestCollisionsCheck::identifier(), &MakePackageDirCheck<DigestCollisionsCheck>::make_package_dir_check);
+ }
+}
+
+#endif
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index b5eb297..50c0cd5 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -19,6 +19,7 @@ add(`dep_packages_check', `hh', `cc')
add(`deps_exist_check', `hh', `cc')
add(`deps_visible_check', `hh', `cc')
add(`description_check', `hh', `cc')
+add(`digest_collisions_check', `hh', `cc')
add(`ebuild_check', `hh', `cc')
add(`ebuild_count', `hh', `cc')
add(`environment', `hh', `cc')