Example #1
0
    def _write_update_to_disk(self):  # pragma: no cover
        # Writes updated binary to disk
        log.debug('Writing update to disk')
        filename_key = '{}*{}*{}*{}*{}'.format(settings.UPDATES_KEY, self.name,
                                               self.highest_version,
                                               self.platform, 'filename')

        filename = self.star_access_update_data.get(filename_key)
        if filename is None:
            raise PatcherError('Filename missing in version file')

        with jms_utils.paths.ChDir(self.update_folder):
            try:
                with open(filename, 'wb') as f:
                    f.write(self.new_binary)
                log.debug('Wrote update file')
            except IOError:
                # Removes file if it got created
                if os.path.exists(filename):
                    os.remove(filename)
                log.error('Failed to open file for writing')
                raise PatcherError('Failed to open file for writing')
            else:
                file_info = self._current_file_info(self.name,
                                                    self.highest_version)

                new_file_hash = file_info['file_hash']
                log.debug('checking file hash match')
                if new_file_hash != get_package_hashes(filename):
                    log.error('File hash does not match')
                    os.remove(filename)
                    raise PatcherError('Bad hash on patched file')
Example #2
0
 def _apply_patches_in_memory(self):
     # Applies a sequence of patches in memory
     log.debug('Applying patches')
     for i in self.patch_binary_data:
         try:
             self.og_binary = bsdiff4.patch(self.og_binary, i)
             log.debug('Applied patch successfully')
         except Exception as err:
             log.debug(err, exc_info=True)
             raise PatcherError('Patch failed to apply')
Example #3
0
    def _write_update_to_disk(self):  # pragma: no cover
        # Writes updated binary to disk
        log.debug("Writing update to disk")
        filename_key = "{}*{}*{}*{}*{}".format(
            settings.UPDATES_KEY,
            self.name,
            self.latest_version,
            self.platform,
            "filename",
        )
        filename = self.star_access_update_data.get(filename_key)

        if filename is None:
            raise PatcherError("Filename missing in version file")

        with ChDir(self.update_folder):
            try:
                with open(filename, "wb") as f:
                    f.write(self.og_binary)
                log.debug("Wrote update file")
            except IOError:
                # Removes file if it got created
                if os.path.exists(filename):
                    remove_any(filename)
                log.debug("Failed to open file for writing")
                raise PatcherError("Failed to open file for writing")
            else:
                file_info = self._get_info(self.name,
                                           self.latest_version,
                                           option="file")

                new_file_hash = file_info["file_hash"]
                log.debug("checking file hash match")
                if new_file_hash != get_package_hashes(filename):
                    log.debug("Version file hash: %s", new_file_hash)
                    log.debug("Actual file hash: %s",
                              get_package_hashes(filename))
                    log.debug("File hash does not match")
                    remove_any(filename)
                    raise PatcherError("Bad hash on patched file",
                                       expected=True)