def _handle_download_file_operation(self, operation): try: # Note: it is a normal file, not a directory CryptoUtils.set_temp_file(operation, self.cfg) success = self._handle_network_transfer_operation(operation) if success: actual_etag = success['actual_etag'] res = self._check_download_integrity(operation, actual_etag) if not res['valid']: # Detected an integrity error. Badly bad. self._server_session.signal_download_integrity_error( operation, res['reason'], res['expected_etag'], res['expected_basis'], res['actual_etag'], res['computed_basis']) return self._make_directories_to(operation.pathname) if operation.to_decrypt: # We have not finished yet, leaving the rest to decrypter. # Note: the decrypter duplicates the following ending logic self.cryptoAdapter.put(operation) return # It is a valid cleartext file, move it to the warebox self.warebox.move(operation.temp_pathname, operation.pathname, operation.conflicted) self.logger.debug(u"Operation has been completed " "successfully: %s" % operation) self.logger.info(u'Synchronized pathname: %s "%s"' % (operation.verb, operation.pathname)) lmtime = self.warebox.get_last_modification_time(operation.pathname) operation.lmtime = lmtime operation.notify_pathname_status_change(PStatuses.ALIGNED) operation.complete() except Exception as e: self.logger.error(u"Error while downloading: %r." " Rejecting the operation: %s" % (e, operation)) self.logger.error(u"Stacktrace: %r" % traceback.format_exc()) operation.reject() finally: # Just in case the move had failed for any reason if not operation.to_decrypt: if operation.temp_pathname is not None \ and os.path.exists(operation.temp_pathname): _try_remove(operation.temp_pathname, self.logger)
def prepare(self, cfg, enc_dir): """ Adds out_pathname and key parameters depending on the task's verb and configuration object @param cfg: configuration manager instance @param enc_dir: the encryption directory path """ self.key = unhexlify(cfg.get('User', 'encryption_key')) self.__check_enc_dir(enc_dir) if self.task.to_encrypt: CryptoUtils.set_temp_file(self.task, cfg, enc_dir) self.iv = Random.new().read(16) self.task.iv = unicode(hexlify(self.iv)) self.out_pathname = self.task.encrypted_pathname elif self.task.to_decrypt: if not self.task.encrypted_pathname: CryptoUtils.set_temp_file(self.task, cfg, enc_dir) self.in_pathname = self.task.encrypted_pathname
def prepare(self, cfg, enc_dir): """ Adds out_pathname and key parameters depending on the task's verb and configuration object @param cfg: configuration manager instance @param enc_dir: the encryption directory path """ self.key = unhexlify(cfg.get('User', 'encryption_key')) self.__check_enc_dir(enc_dir) if self.task.to_encrypt: CryptoUtils.set_temp_file(self.task, cfg, enc_dir) self.iv = Random.new().read(16) self.task.iv = unicode(hexlify(self.iv)) self.out_pathname = self.task.encrypted_pathname elif self.task.to_decrypt: if not self.task.encrypted_pathname: CryptoUtils.set_temp_file(self.task, cfg, enc_dir) self.in_pathname = self.task.encrypted_pathname