move checks earlier to prep_outputs

This commit is contained in:
Tomas Kopecek 2017-10-19 11:26:42 +02:00 committed by Mike McLean
parent 6ad3d65a91
commit b482e36595

View file

@ -5578,6 +5578,29 @@ class CG_Importer(object):
workdir = koji.pathinfo.work()
path = os.path.join(workdir, self.directory, fileinfo.get('relpath', ''), fileinfo['filename'])
fileinfo['hub.path'] = path
filesize = os.path.getsize(path)
if filesize != fileinfo['filesize']:
raise koji.GenericError("File size %s for %s (expected %s) doesn't match. Corrupted upload?" %
(filesize, fileinfo['filename'], fileinfo['filesize']))
# checksum
if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5':
# XXX
# until we change the way we handle checksums, we have to limit this to md5
raise koji.GenericError("Unsupported checksum type: %(checksum_type)s" % fileinfo)
with open(path) as fp:
m = md5_constructor()
while True:
contents = fp.read(8192)
if not contents:
break
m.update(contents)
if fileinfo['checksum'] != m.hexdigest():
raise koji.GenericError("File checksum mismatch for %s: %s != %s" %
(fileinfo['filename'], fileinfo['checksum'], m.hexdigest()))
fileinfo['hub.checked_md5'] = True
if fileinfo['buildroot_id'] not in self.br_prep:
raise koji.GenericError("Missing buildroot metadata for id %(buildroot_id)r" % fileinfo)
if fileinfo['type'] not in ['rpm', 'log']:
@ -5626,7 +5649,6 @@ class CG_Importer(object):
btype = key
type_info = extra['typeinfo'][key]
btype = lookup_name('btype', btype, strict=False)
if btype is None:
raise koji.GenericError("No typeinfo for: %(filename)s" % fileinfo)
@ -5634,11 +5656,6 @@ class CG_Importer(object):
raise koji.GenericError('Output type %s not listed in build '
'types' % btype)
if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5':
# XXX
# until we change the way we handle checksums, we have to limit this to md5
raise koji.GenericError("Unsupported checksum type: %(checksum_type)s" % fileinfo)
fileinfo['hub.btype'] = btype
fileinfo['hub.type_info'] = type_info
@ -6239,14 +6256,18 @@ def import_archive_internal(filepath, buildinfo, type, typeInfo, buildroot_id=No
archiveinfo['filename'] = filename
archiveinfo['size'] = os.path.getsize(filepath)
archivefp = open(filepath)
m = md5_constructor()
while True:
contents = archivefp.read(8192)
if not contents:
break
m.update(contents)
archivefp.close()
archiveinfo['checksum'] = m.hexdigest()
# trust values computed on hub (CG_Importer.prep_outputs)
if not fileinfo or not getattr(fileinfo, 'hub.checked_md5'):
m = md5_constructor()
while True:
contents = archivefp.read(8192)
if not contents:
break
m.update(contents)
archivefp.close()
archiveinfo['checksum'] = m.hexdigest()
else:
archiveinfo['checksum'] = fileinfo['checksum']
archiveinfo['checksum_type'] = koji.CHECKSUM_TYPES['md5']
if fileinfo:
# check against metadata