Update the checksums to a version that supports empty layers.
This commit is contained in:
parent
859f2b9db2
commit
52bee66c9f
1 changed files with 32 additions and 30 deletions
|
@ -28,8 +28,10 @@ def compute_tarsum(fp, json_data):
|
||||||
header_fields = ('name', 'mode', 'uid', 'gid', 'size', 'mtime',
|
header_fields = ('name', 'mode', 'uid', 'gid', 'size', 'mtime',
|
||||||
'type', 'linkname', 'uname', 'gname', 'devmajor',
|
'type', 'linkname', 'uname', 'gname', 'devmajor',
|
||||||
'devminor')
|
'devminor')
|
||||||
tar = tarfile.open(mode='r|*', fileobj=fp)
|
tar = None
|
||||||
hashes = []
|
hashes = []
|
||||||
|
try:
|
||||||
|
tar = tarfile.open(mode='r|*', fileobj=fp)
|
||||||
for member in tar:
|
for member in tar:
|
||||||
header = ''
|
header = ''
|
||||||
for field in header_fields:
|
for field in header_fields:
|
||||||
|
@ -50,16 +52,16 @@ def compute_tarsum(fp, json_data):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
h = sha256_string(header)
|
h = sha256_string(header)
|
||||||
hashes.append(h)
|
hashes.append(h)
|
||||||
#log = '\n+ filename: {0}\n'.format(member.name)
|
|
||||||
#log += '+ header: {0}\n'.format(header)
|
|
||||||
#log += '+ hash: {0}\n'.format(h)
|
|
||||||
#log += '*' * 16
|
|
||||||
#logger.debug('checksums.compute_tarsum: \n{0}'.format(log))
|
|
||||||
tar.close()
|
|
||||||
hashes.sort()
|
hashes.sort()
|
||||||
|
except tarfile.ReadError as e:
|
||||||
|
if e.message != 'empty file':
|
||||||
|
# NOTE(samalba): ignore empty tarfiles but still let the tarsum
|
||||||
|
# compute with json data
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
if tar:
|
||||||
|
tar.close()
|
||||||
data = json_data + ''.join(hashes)
|
data = json_data + ''.join(hashes)
|
||||||
#logger.debug('checksums.compute_tarsum: '
|
|
||||||
# 'Hashes: \n{0}\n{1}'.format('\n'.join(hashes), '-' * 16))
|
|
||||||
tarsum = 'tarsum+sha256:{0}'.format(sha256_string(data))
|
tarsum = 'tarsum+sha256:{0}'.format(sha256_string(data))
|
||||||
logger.debug('checksums.compute_tarsum: return {0}'.format(tarsum))
|
logger.debug('checksums.compute_tarsum: return {0}'.format(tarsum))
|
||||||
return tarsum
|
return tarsum
|
||||||
|
|
Reference in a new issue