From 0d296108996e52a6509eedaa1ef9092b76f27cb8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 16 Apr 2021 14:14:21 +0200 Subject: [PATCH] Catch environment errors when restoring back-ups There could be an environment error when saving that file because of access rights or insufficient disk space. Catch that error and display an error message to the user. The log then contains more information on exactly why it failed, but the user just knows it fails. Fixes Sentry issue CURA-21W. --- plugins/CuraDrive/src/RestoreBackupJob.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/CuraDrive/src/RestoreBackupJob.py b/plugins/CuraDrive/src/RestoreBackupJob.py index c60de116e0..f59acbc8b7 100644 --- a/plugins/CuraDrive/src/RestoreBackupJob.py +++ b/plugins/CuraDrive/src/RestoreBackupJob.py @@ -1,3 +1,6 @@ +# Copyright (c) 2021 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + import base64 import hashlib import threading @@ -56,14 +59,20 @@ class RestoreBackupJob(Job): return # We store the file in a temporary path fist to ensure integrity. - temporary_backup_file = NamedTemporaryFile(delete = False) - with open(temporary_backup_file.name, "wb") as write_backup: - app = CuraApplication.getInstance() - bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE) - while bytes_read: - write_backup.write(bytes_read) + try: + temporary_backup_file = NamedTemporaryFile(delete = False) + with open(temporary_backup_file.name, "wb") as write_backup: + app = CuraApplication.getInstance() bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE) - app.processEvents() + while bytes_read: + write_backup.write(bytes_read) + bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE) + app.processEvents() + except EnvironmentError as e: + Logger.log("e", f"Unable to save backed up files due to computer limitations: {str(e)}") + self.restore_backup_error_message = self.DEFAULT_ERROR_MESSAGE + self._job_done.set() + return if not self._verifyMd5Hash(temporary_backup_file.name, self._backup.get("md5_hash", "")): # Don't restore the backup if the MD5 hashes do not match.