Merge branch 'master' of https://bitbucket.org/yackob03/quay
This commit is contained in:
commit
6f496e7efd
2 changed files with 56 additions and 30 deletions
24
tools/orphans.py
Normal file
24
tools/orphans.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from data.database import Image
|
||||||
|
from app import app
|
||||||
|
|
||||||
|
live_image_id_set = set()
|
||||||
|
|
||||||
|
for image in Image.select():
|
||||||
|
live_image_id_set.add(image.docker_image_id)
|
||||||
|
|
||||||
|
store = app.config['STORAGE']
|
||||||
|
|
||||||
|
storage_image_id_set = set()
|
||||||
|
for customer in store.list_directory('images/'):
|
||||||
|
for repo in store.list_directory(customer):
|
||||||
|
for image in store.list_directory(repo):
|
||||||
|
storage_image_id_set.add(image.split('/')[-1])
|
||||||
|
|
||||||
|
orphans = storage_image_id_set.difference(live_image_id_set)
|
||||||
|
missing_image_data = live_image_id_set.difference(storage_image_id_set)
|
||||||
|
|
||||||
|
for orphan in orphans:
|
||||||
|
print "Orphan: %s" % orphan
|
||||||
|
|
||||||
|
for missing in missing_image_data:
|
||||||
|
print "Missing: %s" % missing
|
|
@ -28,38 +28,40 @@ 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 = []
|
||||||
for member in tar:
|
try:
|
||||||
header = ''
|
tar = tarfile.open(mode='r|*', fileobj=fp)
|
||||||
for field in header_fields:
|
for member in tar:
|
||||||
value = getattr(member, field)
|
header = ''
|
||||||
if field == 'type':
|
for field in header_fields:
|
||||||
field = 'typeflag'
|
value = getattr(member, field)
|
||||||
elif field == 'name':
|
if field == 'type':
|
||||||
if member.isdir() and not value.endswith('/'):
|
field = 'typeflag'
|
||||||
value += '/'
|
elif field == 'name':
|
||||||
header += '{0}{1}'.format(field, value)
|
if member.isdir() and not value.endswith('/'):
|
||||||
h = None
|
value += '/'
|
||||||
try:
|
header += '{0}{1}'.format(field, value)
|
||||||
if member.size > 0:
|
h = None
|
||||||
f = tar.extractfile(member)
|
try:
|
||||||
h = sha256_file(f, header)
|
if member.size > 0:
|
||||||
else:
|
f = tar.extractfile(member)
|
||||||
|
h = sha256_file(f, header)
|
||||||
|
else:
|
||||||
|
h = sha256_string(header)
|
||||||
|
except KeyError:
|
||||||
h = sha256_string(header)
|
h = sha256_string(header)
|
||||||
except KeyError:
|
hashes.append(h)
|
||||||
h = sha256_string(header)
|
hashes.sort()
|
||||||
hashes.append(h)
|
except tarfile.ReadError as e:
|
||||||
#log = '\n+ filename: {0}\n'.format(member.name)
|
if e.message != 'empty file':
|
||||||
#log += '+ header: {0}\n'.format(header)
|
# NOTE(samalba): ignore empty tarfiles but still let the tarsum
|
||||||
#log += '+ hash: {0}\n'.format(h)
|
# compute with json data
|
||||||
#log += '*' * 16
|
raise
|
||||||
#logger.debug('checksums.compute_tarsum: \n{0}'.format(log))
|
finally:
|
||||||
tar.close()
|
if tar:
|
||||||
hashes.sort()
|
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
|
||||||
|
@ -86,4 +88,4 @@ if __name__ == '__main__':
|
||||||
json_data = file(sys.argv[1]).read()
|
json_data = file(sys.argv[1]).read()
|
||||||
fp = open(sys.argv[2])
|
fp = open(sys.argv[2])
|
||||||
print compute_simple(fp, json_data)
|
print compute_simple(fp, json_data)
|
||||||
print compute_tarsum(fp, json_data)
|
print compute_tarsum(fp, json_data)
|
Reference in a new issue