From: Ansgar Burchardt Date: Sun, 4 Sep 2011 21:58:09 +0000 (+0000) Subject: Add missing checksums for source packages. X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=commitdiff_plain;h=6cfc82886d71c7436a97ddfe7a5a1dde297886d2 Add missing checksums for source packages. Add a new subcommand, dak check-archive add-missing-source-checksums, to add missing checksums for source packages to source_metadata. Bug: http://bugs.debian.org/637563 --- diff --git a/dak/check_archive.py b/dak/check_archive.py index 89c3dcbd..3e537d80 100755 --- a/dak/check_archive.py +++ b/dak/check_archive.py @@ -72,6 +72,7 @@ The following MODEs are available: validate-indices - ensure files mentioned in Packages & Sources exist files-not-symlinks - check files in the database aren't symlinks validate-builddeps - validate build-dependencies of .dsc files in the archive + add-missing-source-checksums - add missing checksums for source packages """ sys.exit(exit_code) @@ -478,6 +479,17 @@ def check_build_depends(): ################################################################################ +def add_missing_source_checksums(): + """ Add missing source checksums to source_metadata """ + session = DBConn().session() + for checksum in ['Files', 'Checksums-Sha1', 'Checksums-Sha256']: + rows = session.execute('SELECT source_metadata_add_missing_checksum(:type)', {'type': checksum}).scalar() + if rows > 0: + print "Added {0} missing entries for {1}".format(rows, checksum) + session.commit() + +################################################################################ + def main (): global db_files, waste, excluded @@ -525,6 +537,8 @@ def main (): check_files_not_symlinks() elif mode == "validate-builddeps": check_build_depends() + elif mode == "add-missing-source-checksums": + add_missing_source_checksums() else: utils.warn("unknown mode '%s'" % (mode)) usage(1) diff --git a/dak/dakdb/update71.py b/dak/dakdb/update71.py new file mode 100755 index 00000000..079c195c --- /dev/null +++ b/dak/dakdb/update71.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Add missing checksums to source_metadata + +@contact: Debian FTP Master +@copyright: 2011 Ansgar Burchardt +@license: GNU General Public License version 2 or later +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program 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 + +################################################################################ + +import psycopg2 +from daklib.dak_exceptions import DBUpdateError +from daklib.config import Config + +################################################################################ +def do_update(self): + """ + Add missing checksums to source_metadata + """ + print __doc__ + try: + c = self.db.cursor() + c.execute(R"""CREATE OR REPLACE FUNCTION metadata_keys_get(key_ text) + RETURNS integer + LANGUAGE plpgsql + STRICT +AS $function$ +DECLARE + v_key_id metadata_keys.key_id%TYPE; +BEGIN + SELECT key_id INTO v_key_id FROM metadata_keys WHERE key = key_; + IF NOT FOUND THEN + INSERT INTO metadata_keys (key) VALUES (key_) RETURNING key_id INTO v_key_id; + END IF; + RETURN v_key_id; +END; +$function$ +""") + + c.execute("""COMMENT ON FUNCTION metadata_keys_get(text) +IS 'return key_id for the given key. If key is not present, create a new entry.' +""") + + c.execute(R"""CREATE OR REPLACE FUNCTION source_metadata_add_missing_checksum(type text) + RETURNS INTEGER + LANGUAGE plpgsql + STRICT +AS $function$ +DECLARE + v_checksum_key metadata_keys.key_id%TYPE; + rows INTEGER; +BEGIN + IF type NOT IN ('Files', 'Checksums-Sha1', 'Checksums-Sha256') THEN + RAISE EXCEPTION 'Unknown checksum field %', type; + END IF; + v_checksum_key := metadata_keys_get(type); + + INSERT INTO source_metadata + (src_id, key_id, value) + SELECT + s.id, + v_checksum_key, + E'\n' || + (SELECT STRING_AGG(' ' || tmp.checksum || ' ' || tmp.size || ' ' || tmp.basename, E'\n' ORDER BY tmp.basename) + FROM + (SELECT + CASE type + WHEN 'Files' THEN f.md5sum + WHEN 'Checksums-Sha1' THEN f.sha1sum + WHEN 'Checksums-Sha256' THEN f.sha256sum + END AS checksum, + f.size, + SUBSTRING(f.filename FROM E'/([^/]*)\\Z') AS basename + FROM files f JOIN dsc_files ON f.id = dsc_files.file + WHERE dsc_files.source = s.id AND f.id != s.file + ) AS tmp + ) + + FROM + source s + WHERE NOT EXISTS (SELECT 1 FROM source_metadata md WHERE md.src_id=s.id AND md.key_id = v_checksum_key); + + GET DIAGNOSTICS rows = ROW_COUNT; + RETURN rows; +END; +$function$ +""") + + c.execute("""COMMENT ON FUNCTION source_metadata_add_missing_checksum(TEXT) +IS 'add missing checksum fields to source_metadata. type can be Files (md5sum), Checksums-Sha1, Checksums-Sha256' +""") + + c.execute("UPDATE config SET value = '71' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError as msg: + self.db.rollback() + raise DBUpdateError('Unable to apply sick update 71, rollback issued. Error message : %s' % (str(msg))) diff --git a/dak/update_db.py b/dak/update_db.py index 3e31a3be..2a946822 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -46,7 +46,7 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 70 +required_database_schema = 71 ################################################################################