summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-07-15 18:59:37 +0100
committerRichard Hughes <richard@hughsie.com>2014-07-15 18:59:41 +0100
commit5bc8985067b764a81258a13b9eb390d755370cbe (patch)
tree2834cb5eeabdcc24c89d0cbdf08ca9d1b3d05fb8
parent200c02de109008f98e2abff451bdbbc63affb114 (diff)
downloadappstream-glib-5bc8985067b764a81258a13b9eb390d755370cbe.tar.gz
trivial: Use more than just the file size when checking packages
-rwxr-xr-xcontrib/packages/fedora-download-cache.py20
1 files 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