From: Philipp Gesang Date: Thu, 20 Apr 2017 14:53:06 +0000 (+0200) Subject: pass encryption context to deltatar volume handlers X-Git-Tag: v2.2~7^2~160 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=b7c47f3815e9b0f26e58fa4961007c47bb2d3365;p=python-delta-tar pass encryption context to deltatar volume handlers --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 56bed3c..697a3df 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -617,7 +617,7 @@ class DeltaTar(object): cwd = os.getcwd() - def new_volume_handler(deltarobj, cwd, backup_path, tarobj, base_name, volume_number): + def new_volume_handler(deltarobj, cwd, backup_path, encryption, tarobj, base_name, volume_number): ''' Handles the new volumes ''' @@ -634,10 +634,10 @@ class DeltaTar(object): deltarobj.logger.debug("opening volume %s" % volume_path) - tarobj.open_volume(volume_path) + tarobj.open_volume(volume_path, encryption=encryption) # wraps some args from context into the handler - new_volume_handler = partial(new_volume_handler, self, cwd, backup_path) + new_volume_handler = partial(new_volume_handler, self, cwd, backup_path, self.crypto_ctx) index_accu.write(bytes('{"type": "python-delta-tar-index", "version": 1, "backup-type": "full", "extra_data": %s}\n' % extra_data_str, 'UTF-8')) @@ -1194,7 +1194,7 @@ class DeltaTar(object): cwd = os.getcwd() - def new_volume_handler(deltarobj, cwd, backup_path, tarobj, base_name, volume_number): + def new_volume_handler(deltarobj, cwd, backup_path, encryption, tarobj, base_name, volume_number): ''' Handles the new volumes ''' @@ -1205,15 +1205,15 @@ class DeltaTar(object): # we convert relative paths into absolute because CWD is changed if not os.path.isabs(volume_path): volume_path = os.path.join(cwd, volume_path) - tarobj.open_volume(volume_path) + tarobj.open_volume(volume_path, encryption=encryption) + + if self.password is not None: + self.crypto_ctx = crypto.Decrypt (self.password) backup_path = os.path.dirname(backup_tar_path) if not os.path.isabs(backup_path): backup_path = os.path.join(cwd, backup_path) - new_volume_handler = partial(new_volume_handler, self, cwd, backup_path) - - if self.password is not None: - self.crypto_ctx = crypto.Decrypt (self.password) + new_volume_handler = partial(new_volume_handler, self, cwd, backup_path, self.crypto_ctx) tarobj = tarfile.TarFile.open(backup_tar_path, mode='r' + self.mode, @@ -1462,7 +1462,7 @@ class RestoreHelper(object): last_lno = 0, new_volume_handler = partial(self.new_volume_handler, self._deltatar, self._cwd, is_full, - os.path.dirname(index)) + os.path.dirname(index), self._deltatar.crypto_ctx) ) self._data.append(s) else: @@ -1472,7 +1472,8 @@ class RestoreHelper(object): # update the new_volume_handler of tar_obj tarobj.new_volume_handler = partial(self.new_volume_handler, - self._deltatar, self._cwd, True, os.path.dirname(backup_path)) + self._deltatar, self._cwd, True, os.path.dirname(backup_path), + self._deltatar.crypto_ctx) s = dict( curr_vol_no = None, vol_fd = None, @@ -1664,7 +1665,7 @@ class RestoreHelper(object): self._deltatar.logger.warning('tarfile: %s' % e) @staticmethod - def new_volume_handler(deltarobj, cwd, is_full, backup_path, tarobj, base_name, volume_number): + def new_volume_handler(deltarobj, cwd, is_full, backup_path, encryption, tarobj, base_name, volume_number): ''' Handles the new volumes ''' @@ -1675,7 +1676,7 @@ class RestoreHelper(object): # we convert relative paths into absolute because CWD is changed if not os.path.isabs(volume_path): volume_path = os.path.join(cwd, volume_path) - tarobj.open_volume(volume_path) + tarobj.open_volume(volume_path, encryption=encryption) def restore_file(self, file_data, index_data, path, l_no, unprefixed_path): '''