[Dextrose] [PATCH 5/5][dextrose2][sugar] Updater check bundle integrity
Sascha Silbe
sascha-ml-reply-to-2011-2 at silbe.org
Wed Apr 20 03:21:13 EDT 2011
Excerpts from Martin Abente's message of Tue Apr 19 23:21:28 +0200 2011:
[extensions/cpsection/updater/model.py]
> @@ -378,5 +379,22 @@ class _Downloader(gobject.GObject):
[...]
> + def _check_integrity(self):
> + bundle_path = self._output_file.get_path()
> +
> + try:
> + bundle_file = ZipFile(bundle_path, 'r')
> + except:
> + passed = False
> + else:
> + passed = (bundle_file.testzip() is None)
> + bundle_file.close()
> +
> + if passed:
> self.emit('finish', True)
> + else:
> + logging.error('updater: %s bundle file is corrupt' % bundle_path)
> + self.emit('finish', False)
A more concise way of implementing this would be:
def _check_integrity(self):
bundle_path = self._output_file.get_path()
try:
with ZipFile(bundle_path, 'r') as bundle_file:
bundle_file.testzip()
except zipfile.BadZipfile:
logging.exception('Downloaded corrupt bundle %s:', bundle_path)
self.emit('finish', False)
else:
self.emit('finish', True)
Sascha
--
http://sascha.silbe.org/
http://www.infra-silbe.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 500 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/archive/dextrose/attachments/20110420/dfe9e4b5/attachment.pgp>
More information about the Dextrose
mailing list