amprolla

devuan's apt repo merger
git clone git://parazyd.org/amprolla.git
Log | Files | Refs | README | LICENSE

commit 5283b1e533085e4814bfe73dc67a89d279f9dc06
parent aedd903f12d7c7ddc538aab72ebed412559ab565
Author: parazyd <parazyd@dyne.org>
Date:   Wed,  8 Nov 2017 16:52:44 +0100

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.

Diffstat:
Mamprolla_update.py | 1+
Mlib/globalvars.py | 3+++
Mlib/release.py | 38++++++++++++++++++++++++++------------
3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/amprolla_update.py b/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) diff --git a/lib/globalvars.py b/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 diff --git a/lib/release.py b/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):