From 5bc8985067b764a81258a13b9eb390d755370cbe Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 15 Jul 2014 18:59:37 +0100 Subject: trivial: Use more than just the file size when checking packages --- contrib/packages/fedora-download-cache.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/contrib/packages/fedora-download-cache.py b/contrib/packages/fedora-download-cache.py index c29d839..18b0a4b 100755 --- a/contrib/packages/fedora-download-cache.py +++ b/contrib/packages/fedora-download-cache.py @@ -27,6 +27,7 @@ import rpm import rpmUtils import sys import yum +import hashlib import fnmatch import datetime import ConfigParser @@ -89,6 +90,13 @@ def search_package_list(pkg): return True return False +def get_sha256_hash(filename, block_size=256*128): + md5 = hashlib.sha256() + with open(filename,'rb') as f: + for chunk in iter(lambda: f.read(block_size), b''): + md5.update(chunk) + return md5.hexdigest() + def ensure_pkg_exists(yb, existing, pkg): # get base name without the slash @@ -99,10 +107,15 @@ def ensure_pkg_exists(yb, existing, pkg): # is in cache? path = './packages/' + relativepath - if os.path.exists(path) and os.path.getsize(path) == int(pkg.returnSimple('packagesize')): + if os.path.exists(path) and get_sha256_hash(path) == pkg.checksum: #print("INFO: %s up to date" % pkg.nvra) return + # do we have an old version of this? + if existing.has_key(pkg.name) and os.path.exists(existing[pkg.name]): + print("INFO: deleting %s" % os.path.basename(existing[pkg.name])) + os.remove(existing[pkg.name]) + # make sure the metadata exists repo = yb.repos.getRepo(pkg.repoid) @@ -111,11 +124,6 @@ def ensure_pkg_exists(yb, existing, pkg): pkg.localpath = path repo.getPackage(pkg) - # do we have an old version of this? - if existing.has_key(pkg.name) and os.path.exists(existing[pkg.name]): - print("INFO: deleting %s" % os.path.basename(existing[pkg.name])) - os.remove(existing[pkg.name]) - def update(): # create if we're starting from nothing -- cgit v1.2.1