From d624e9d18f93de9f700b0c09cb9118f2493407ad Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 18 Aug 2011 15:06:05 +0100 Subject: [PATCH] factor out dsc comparison into a method on ubuntutools.archive.Dsc --- syncpackage | 26 ++++---------------------- ubuntutools/archive.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/syncpackage b/syncpackage index 222cd04..7d87a55 100755 --- a/syncpackage +++ b/syncpackage @@ -349,28 +349,10 @@ def copy(src_pkg, release, simulate=False, force=False): # Check whether a fakesync would be required. src_pkg.pull_dsc(quiet=not Logger.verbose) ubuntu_pkg.pull_dsc(quiet=not Logger.verbose) - for field, key in (('Checksums-Sha256', 'sha256'), - ('Checksums-Sha1', 'sha1'), - ('Files', 'md5sum')): - if field not in src_pkg.dsc or field not in ubuntu_pkg.dsc: - continue - debian_checksums = \ - dict((entry['name'], (int(entry['size']), entry[key])) - for entry in src_pkg.dsc[field]) - ubuntu_checksums = \ - dict((entry['name'], (int(entry['size']), entry[key])) - for entry in ubuntu_pkg.dsc[field]) - for name, (size, checksum) in debian_checksums.iteritems(): - if name not in ubuntu_checksums: - # new file - continue - if (size != ubuntu_checksums[name][0] or - checksum != ubuntu_checksums[name][1]): - Logger.error('The checksums of the Debian and Ubuntu ' - 'packages mismatch. A fake sync using ' - '--no-lp is required.') - sys.exit(1) - break # one checksum is good enough + if not src_pkg.dsc.compare_dsc(ubuntu_pkg.dsc): + Logger.error('The checksums of the Debian and Ubuntu packages ' + 'mismatch. A fake sync using --no-lp is required.') + sys.exit(1) except udtexceptions.PackageNotFoundException: Logger.normal('Source %s -> %s/%s: not in Ubuntu, new version %s', src_pkg.source, ubuntu_series, ubuntu_pocket, diff --git a/ubuntutools/archive.py b/ubuntutools/archive.py index 1604b53..b1e09a3 100644 --- a/ubuntutools/archive.py +++ b/ubuntutools/archive.py @@ -95,6 +95,30 @@ class Dsc(debian.deb822.Dsc): return hash_func.hexdigest() == digest return False + def compare_dsc(self, other): + """Check whether any files in these two dscs that have the same name + also have the same checksum.""" + for field, key in (('Checksums-Sha256', 'sha256'), + ('Checksums-Sha1', 'sha1'), + ('Files', 'md5sum')): + if field not in self or field not in other: + continue + our_checksums = \ + dict((entry['name'], (int(entry['size']), entry[key])) + for entry in self[field]) + their_checksums = \ + dict((entry['name'], (int(entry['size']), entry[key])) + for entry in other[field]) + for name, (size, checksum) in our_checksums.iteritems(): + if name not in their_checksums: + # file only in one dsc + continue + if (size != their_checksums[name][0] or + checksum != their_checksums[name][1]): + return False + return True # one checksum is good enough + return True + class SourcePackage(object): """Base class for source package downloading.