[game-data-packager] 03/19: Always check that files' sizes and checksums are consistent
Simon McVittie
smcv at debian.org
Tue Jan 13 11:34:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit f5ad4684b21e6f6e3503e00a98759a7b7229b404
Author: Simon McVittie <smcv at debian.org>
Date: Tue Jan 13 08:58:30 2015 +0000
Always check that files' sizes and checksums are consistent
Previously, we did this check if the files section appeared before
the md5sums or cksums, but would have silently overwritten the
old value if the files section appeared after.
---
lib/game_data_packager/__init__.py | 45 +++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index 2273516..8d0d856 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -63,9 +63,9 @@ MD5SUM_DIVIDER = re.compile(r' [ *]?')
class HashedFile(object):
def __init__(self, name):
self.name = name
- self.md5 = None
- self.sha1 = None
- self.sha256 = None
+ self._md5 = None
+ self._sha1 = None
+ self._sha256 = None
self.skip_hash_matching = False
@classmethod
@@ -166,6 +166,36 @@ class HashedFile(object):
return True
+ @property
+ def md5(self):
+ return self._md5
+ @md5.setter
+ def md5(self, value):
+ if self._md5 is not None and value != self._md5:
+ raise AssertionError('trying to set md5 of "%s" to both %s '
+ + 'and %s', self.name, self._md5, value)
+ self._md5 = value
+
+ @property
+ def sha1(self):
+ return self._sha1
+ @sha1.setter
+ def sha1(self, value):
+ if self._sha1 is not None and value != self._sha1:
+ raise AssertionError('trying to set sha1 of "%s" to both %s '
+ + 'and %s', self.name, self._sha1, value)
+ self._sha1 = value
+
+ @property
+ def sha256(self):
+ return self._sha256
+ @sha256.setter
+ def sha256(self, value):
+ if self._sha256 is not None and value != self._sha256:
+ raise AssertionError('trying to set sha256 of "%s" to both %s '
+ + 'and %s', self.name, self._sha256, value)
+ self._sha256 = value
+
class WantedFile(HashedFile):
def __init__(self, name):
super(WantedFile, self).__init__(name)
@@ -198,6 +228,9 @@ class WantedFile(HashedFile):
return self._size
@size.setter
def size(self, value):
+ if self._size is not None and value != self._size:
+ raise AssertionError('trying to set size of "%s" to both %d '
+ + 'and %d', self.name, self._size, value)
self._size = int(value)
@property
@@ -403,8 +436,6 @@ class GameData(object):
hexdigest, filename = MD5SUM_DIVIDER.split(line, 1)
f = self._ensure_file(filename)
- already = getattr(f, alg)
- assert (already == hexdigest or already is None), (alg, already, hexdigest)
setattr(f, alg, hexdigest)
for filename, f in self.files.items():
@@ -556,9 +587,7 @@ class GameData(object):
_, size, filename = line.split(None, 2)
f = self._ensure_file(filename)
- size = int(size)
- assert (f.size == size or f.size is None), (f.size, size)
- f.size = size
+ f.size = int(size)
package.install.add(filename)
self._populate_files(d.get('install_files'), install=True,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list