]> git.decadent.org.uk Git - dak.git/blobdiff - dak/check_archive.py
remove backwards-compatiblity stuff which is no longer needed
[dak.git] / dak / check_archive.py
index 2d9321d68c68f1caf5e7d77799c6eece507cb739..2eb450bd434b9e6736da1222f16b967d478da4de 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Various different sanity checks
+""" Various different sanity checks """
 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
 
 # This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,7 @@ import commands, os, pg, stat, sys, time
 import apt_pkg, apt_inst
 from daklib import database
 from daklib import utils
+from daklib.regexes import re_issource
 
 ################################################################################
 
@@ -52,7 +53,7 @@ Run various sanity checks of the archive and/or database.
 
 The following MODEs are available:
 
-  md5sums            - validate the md5sums stored in the database
+  checksums          - validate the checksums stored in the database
   files              - check files in the database against what's in the archive
   dsc-syntax         - validate the syntax of .dsc files in the archive
   missing-overrides  - check for missing overrides
@@ -194,16 +195,18 @@ SELECT l.path, f.filename FROM files f, dsc_files df, location l WHERE df.source
 
 ################################################################################
 
-def check_md5sums():
+def check_checksums():
     print "Getting file information from database..."
-    q = projectB.query("SELECT l.path, f.filename, f.md5sum, f.size FROM files f, location l WHERE f.location = l.id")
+    q = projectB.query("SELECT l.path, f.filename, f.md5sum, f.sha1sum, f.sha256sum, f.size FROM files f, location l WHERE f.location = l.id")
     ql = q.getresult()
 
-    print "Checking file md5sums & sizes..."
+    print "Checking file checksums & sizes..."
     for i in ql:
         filename = os.path.abspath(i[0] + i[1])
         db_md5sum = i[2]
-        db_size = int(i[3])
+        db_sha1sum = i[3]
+        db_sha256sum = i[4]
+        db_size = int(i[5])
         try:
             f = utils.open_file(filename)
         except:
@@ -216,6 +219,18 @@ def check_md5sums():
         if size != db_size:
             utils.warn("**WARNING** size mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, size, db_size))
 
+        # Check the sha1sum
+        f.seek(0)
+        sha1sum = apt_pkg.sha1sum(f)
+        if sha1sum != db_sha1sum:
+            utils.warn("**WARNING** sha1sum mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, sha1sum, db_sha1sum))
+
+        # Check the sha256sum
+        f.seek(0)
+        sha256sum = apt_pkg.sha256sum(f)
+        if sha256sum != db_sha256sum:
+            utils.warn("**WARNING** sha256sum mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, sha256sum, db_sha256sum))
+
     print "Done."
 
 ################################################################################
@@ -271,7 +286,7 @@ def check_missing_tar_gz_in_dsc():
         dsc_files = utils.build_file_list(dsc, is_a_dsc=1)
         has_tar = 0
         for f in dsc_files.keys():
-            m = utils.re_issource.match(f)
+            m = re_issource.match(f)
             if not m:
                 utils.fubar("%s not recognised as source." % (f))
             ftype = m.group(3)
@@ -291,7 +306,7 @@ def validate_sources(suite, component):
     filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::Root"], suite, component)
     print "Processing %s..." % (filename)
     # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
-    temp_filename = utils.temp_filename()
+    (fd, temp_filename) = utils.temp_filename()
     (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
     if (result != 0):
         sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
@@ -330,7 +345,7 @@ def validate_packages(suite, component, architecture):
                % (Cnf["Dir::Root"], suite, component, architecture)
     print "Processing %s..." % (filename)
     # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
-    temp_filename = utils.temp_filename()
+    (fd, temp_filename) = utils.temp_filename()
     (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
     if (result != 0):
         sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
@@ -425,8 +440,8 @@ def main ():
     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
     database.init(Cnf, projectB)
 
-    if mode == "md5sums":
-        check_md5sums()
+    if mode == "checksums":
+        check_checksums()
     elif mode == "files":
         check_files()
     elif mode == "dsc-syntax":