Detect corrupt downloads

This commit is contained in:
Tom Payne
2012-11-09 11:23:51 +01:00
parent bf4e7bcb70
commit df8685638c
2 changed files with 8 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
import collections
import contextlib
import hashlib
import logging
import optparse
import os
@@ -126,8 +127,12 @@ class Target(object):
def debug(self, *args, **kwargs):
self.logger.debug(*args, **kwargs)
def download(self, url):
def download(self, url, md5=None):
content = urllib2.urlopen(url).read()
if md5 and hashlib.md5(content).hexdigest() != md5:
raise pake.BuildError(t, 'corrupt download')
# FIXME Python on Windoze corrupts the content when writing it
# FIXME probably something to do with encodings
with open(self.name, 'w') as f:
f.write(content)