Browse Source

move hashing of files to a separate function

This commit also introduces a global variable called "rehash". It will
be used to signal whether the rehashing of files needs to be done.
keep-around/e977c9e07f177e8bc2b51265de1bc93475397f61
parazyd 5 years ago
parent
commit
5283b1e533
Signed by untrusted user: parazyd GPG Key ID: F0CB28FCF78637DE
  1. 1
      amprolla_update.py
  2. 3
      lib/globalvars.py
  3. 38
      lib/release.py

1
amprolla_update.py

@ -73,6 +73,7 @@ def perform_update(suite, paths):
diffs = compare_dict(parse_release(remote_rel.text),
parse_release(local_rel_text))
if diffs:
globalvars.rehash = True
for k in diffs:
if k.endswith('Packages.gz') or k.endswith('Sources.gz'):
needsmerge[i]['mergelist'].append(k)

3
lib/globalvars.py

@ -6,3 +6,6 @@ amprolla globals to pass around
# state for the current suite we're in
suite = ""
# tells us if we need to recreate checksums for Release files
rehash = True

38
lib/release.py

@ -10,6 +10,7 @@ from lzma import compress as lzma_comp
from os.path import getsize, isfile
from subprocess import Popen
import lib.globalvars as globalvars
from lib.config import (checksums, distrolabel, gpgdir, release_aliases,
release_keys, signingkey)
from lib.log import info
@ -63,25 +64,38 @@ def write_release(oldrel, newrel, filelist, r, sign=True, rewrite=True):
if k in rel_cont:
new.write('%s: %s\n' % (k, rel_cont[k]))
if globalvars.rehash:
rehash_release(filelist, new, r)
new.close()
if sign:
sign_release(newrel)
def rehash_release(_filelist, fd, r):
"""
Calculates checksums of a given filelist and writes them to the given
file descriptor. Takes r as the third argument, which is a string to
remove from the path of the hashed file when writing it to a file.
"""
info('Hashing checksums')
for csum in checksums:
new.write('%s:\n' % csum['name'])
for f in filelist:
fd.write('%s:\n' % csum['name'])
for f in _filelist:
if isfile(f):
cont = open(f, 'rb').read()
new.write(' %s %8s %s\n' % (csum['f'](cont).hexdigest(),
getsize(f), f.replace(r+'/', '')))
fd.write(' %s %8s %s\n' % (csum['f'](cont).hexdigest(),
getsize(f), f.replace(r+'/', '')))
elif f.endswith('.xz') and isfile(f.replace('.xz', '.gz')):
xzstr = lzma_comp(open(f.replace('.xz', '.gz'), 'rb').read())
new.write(' %s %8s %s\n' % (csum['f'](xzstr).hexdigest(),
len(xzstr), f.replace(r+'/', '')))
fd.write(' %s %8s %s\n' % (csum['f'](xzstr).hexdigest(),
len(xzstr), f.replace(r+'/', '')))
elif not f.endswith('.gz') and isfile(f+'.gz'):
uncomp = gzip_decomp(open(f+'.gz', 'rb').read())
new.write(' %s %8s %s\n' % (csum['f'](uncomp).hexdigest(),
len(uncomp), f.replace(r+'/', '')))
new.close()
if sign:
sign_release(newrel)
fd.write(' %s %8s %s\n' % (csum['f'](uncomp).hexdigest(),
len(uncomp), f.replace(r+'/', '')))
return
def sign_release(infile):

Loading…
Cancel
Save