mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
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.
This commit is contained in:
parent
acb0c57026
commit
0d29610899
1 changed files with 16 additions and 7 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import threading
|
import threading
|
||||||
|
@ -56,14 +59,20 @@ class RestoreBackupJob(Job):
|
||||||
return
|
return
|
||||||
|
|
||||||
# We store the file in a temporary path fist to ensure integrity.
|
# We store the file in a temporary path fist to ensure integrity.
|
||||||
temporary_backup_file = NamedTemporaryFile(delete = False)
|
try:
|
||||||
with open(temporary_backup_file.name, "wb") as write_backup:
|
temporary_backup_file = NamedTemporaryFile(delete = False)
|
||||||
app = CuraApplication.getInstance()
|
with open(temporary_backup_file.name, "wb") as write_backup:
|
||||||
bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
|
app = CuraApplication.getInstance()
|
||||||
while bytes_read:
|
|
||||||
write_backup.write(bytes_read)
|
|
||||||
bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
|
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", "")):
|
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.
|
# Don't restore the backup if the MD5 hashes do not match.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue