Commit 1bbbb2a8 authored by Simon McVittie's avatar Simon McVittie

Move md5sums from GameDataPackage to PackagingTask

This removes another instance of storing mutable state in the
GameDataPackage. My goal is that the GameDataPackage will never be
modified after it has been loaded.
parent e990a4ad
......@@ -172,10 +172,6 @@ class GameDataPackage(object):
# archives actually used to built a package
self.used_sources = set()
# Remember the md5 of installed files
# that will end up in DEBIAN/md5sums
self.md5sums = dict()
@property
def aliases(self):
return self._aliases
......
......@@ -225,6 +225,12 @@ class PackagingTask(object):
# Block device from which to rip audio
self.cd_device = None
# Remember the md5 of installed files that will end up in
# DEBIAN/md5sums
# e.g. { 'quake3-data': {
# 'usr/share/games/quake3-data/baseq3/pak0.pk3': '1197ca...' }
self.package_md5sums = {}
# Found CD tracks
# e.g. { 'quake-music': { 2: '/usr/.../id1/music/track02.ogg' } }
self.cd_tracks = {}
......@@ -1328,7 +1334,7 @@ class PackagingTask(object):
os.chmod(copy_to, 0o644)
fullname = os.path.join(install_to, install_as).strip('/')
package.md5sums[fullname] = md5
self.package_md5sums.setdefault(package.name, {})[fullname] = md5
install_to = self.packaging.substitute(package.install_to,
package.name)
......@@ -2009,7 +2015,8 @@ class PackagingTask(object):
self.__check_component(package)
pkg = self.packaging.build_package(per_package_dir, self.game,
package, destination, compress=compress)
package, destination, compress=compress,
md5sums=self.package_md5sums.get(package.name))
assert pkg is not None
packages.add(pkg)
......
......@@ -304,7 +304,7 @@ class PackagingSystem(metaclass=ABCMeta):
@abstractmethod
def build_package(self, per_package_dir, game, package,
destination, compress=True):
destination, compress=True, md5sums=None):
"""Build the .deb or equivalent in destination, and return its
filename.
......@@ -313,6 +313,9 @@ class PackagingSystem(metaclass=ABCMeta):
to be packaged (so it contains DESTDIR/usr, etc.)
game and package are a GameData and a GameDataPackage respectively.
md5sums is either None, or a map like
{ 'usr/share/games/quake3-data/baseq3/pak0.pk3': '1197ca...' }
"""
raise NotImplementedError
......
......@@ -155,7 +155,7 @@ class ArchPackaging(PackagingSystem):
+ sorted(files), env={'LANG':'C'}, cwd=destdir)
def build_package(self, per_package_dir, game, package, destination,
compress=True):
compress=True, md5sums=None):
destdir = os.path.join(per_package_dir, 'DESTDIR')
arch = self.get_effective_architecture(package)
......
......@@ -347,12 +347,14 @@ class DebPackaging(PackagingSystem):
return control
def __fill_dest_dir_deb(self, game, package, destdir):
def __fill_dest_dir_deb(self, game, package, destdir, md5sums=None):
if package.component == 'local':
self.override_lintian(destdir, package.name,
'unknown-section', 'local/%s' % package.section)
# same output as in dh_md5sums
if md5sums is None:
md5sums = {}
# we only compute here the md5 we don't have yet,
# for the (small) GDP-generated files
......@@ -364,18 +366,18 @@ class DebPackaging(PackagingSystem):
if os.path.islink(full):
continue
file = full[len(destdir)+1:]
if file not in package.md5sums:
if file not in md5sums:
with open(full, 'rb') as opened:
hf = HashedFile.from_file(full, opened)
package.md5sums[file] = hf.md5
md5sums[file] = hf.md5
debdir = os.path.join(destdir, 'DEBIAN')
mkdir_p(debdir)
md5sums = os.path.join(destdir, 'DEBIAN/md5sums')
with open(md5sums, 'w', encoding='utf8') as outfile:
for file in sorted(package.md5sums.keys()):
outfile.write('%s %s\n' % (package.md5sums[file], file))
os.chmod(md5sums, 0o644)
md5sums_path = os.path.join(destdir, 'DEBIAN/md5sums')
with open(md5sums_path, 'w', encoding='utf8') as outfile:
for file in sorted(md5sums.keys()):
outfile.write('%s %s\n' % (md5sums[file], file))
os.chmod(md5sums_path, 0o644)
control = os.path.join(destdir, 'DEBIAN/control')
self.__generate_control(game, package, destdir).dump(
......@@ -383,10 +385,10 @@ class DebPackaging(PackagingSystem):
os.chmod(control, 0o644)
def build_package(self, per_package_dir, game, package, destination,
compress=True):
compress=True, md5sums=None):
destdir = os.path.join(per_package_dir, 'DESTDIR')
arch = self.get_effective_architecture(package)
self.__fill_dest_dir_deb(game, package, destdir)
self.__fill_dest_dir_deb(game, package, destdir, md5sums)
normalize_permissions(destdir)
# it had better have a /usr and a DEBIAN directory or
......
......@@ -231,7 +231,7 @@ class RpmPackaging(PackagingSystem):
return specfile
def build_package(self, per_package_dir, game, package, destination,
compress=True):
compress=True, md5sums=None):
destdir = os.path.join(per_package_dir, 'DESTDIR')
arch = self.get_effective_architecture(package)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment