mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-10 00:59:02 +08:00
Merge pull request #10031 from Ultimaker/CURA-8313_Fail_gracefully_when_a_file_is_in_use_while_restoring_the_backup
CURA-8313: Ignore files-in-use while restoring a backup
This commit is contained in:
commit
9a27a63b7e
@ -7,7 +7,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile
|
from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile
|
||||||
from typing import Dict, Optional, TYPE_CHECKING, List
|
from typing import Dict, Optional, TYPE_CHECKING, List, Tuple
|
||||||
|
|
||||||
from UM import i18nCatalog
|
from UM import i18nCatalog
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
@ -156,7 +156,10 @@ class Backup:
|
|||||||
Logger.log("d", f"The following error occurred while trying to restore a Cura backup: {str(e)}")
|
Logger.log("d", f"The following error occurred while trying to restore a Cura backup: {str(e)}")
|
||||||
self._showMessage(self.catalog.i18nc("@info:backup_failed", "The following error occurred while trying to restore a Cura backup:") + str(e))
|
self._showMessage(self.catalog.i18nc("@info:backup_failed", "The following error occurred while trying to restore a Cura backup:") + str(e))
|
||||||
return False
|
return False
|
||||||
extracted = self._extractArchive(archive, version_data_dir)
|
extracted, failed_files = self._extractArchive(archive, version_data_dir)
|
||||||
|
self._showMessage(
|
||||||
|
self.catalog.i18nc("@info:backup_failed",
|
||||||
|
"The following error occurred while trying to restore a Cura backup:" + "\n{}".format("\n".join(failed_files))))
|
||||||
|
|
||||||
# Under Linux, preferences are stored elsewhere, so we copy the file to there.
|
# Under Linux, preferences are stored elsewhere, so we copy the file to there.
|
||||||
if Platform.isLinux():
|
if Platform.isLinux():
|
||||||
@ -175,7 +178,7 @@ class Backup:
|
|||||||
return extracted
|
return extracted
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extractArchive(archive: "ZipFile", target_path: str) -> bool:
|
def _extractArchive(archive: "ZipFile", target_path: str) -> Tuple[bool, List[str]]:
|
||||||
"""Extract the whole archive to the given target path.
|
"""Extract the whole archive to the given target path.
|
||||||
|
|
||||||
:param archive: The archive as ZipFile.
|
:param archive: The archive as ZipFile.
|
||||||
@ -188,20 +191,23 @@ class Backup:
|
|||||||
config_filename = CuraApplication.getInstance().getApplicationName() + ".cfg" # Should be there if valid.
|
config_filename = CuraApplication.getInstance().getApplicationName() + ".cfg" # Should be there if valid.
|
||||||
if config_filename not in [file.filename for file in archive.filelist]:
|
if config_filename not in [file.filename for file in archive.filelist]:
|
||||||
Logger.logException("e", "Unable to extract the backup due to corruption of compressed file(s).")
|
Logger.logException("e", "Unable to extract the backup due to corruption of compressed file(s).")
|
||||||
return False
|
return False, []
|
||||||
|
|
||||||
Logger.log("d", "Removing current data in location: %s", target_path)
|
Logger.log("d", "Removing current data in location: %s", target_path)
|
||||||
Resources.factoryReset()
|
Resources.factoryReset()
|
||||||
Logger.log("d", "Extracting backup to location: %s", target_path)
|
Logger.log("d", "Extracting backup to location: %s", target_path)
|
||||||
try:
|
|
||||||
name_list = archive.namelist()
|
name_list = archive.namelist()
|
||||||
|
failed_files = []
|
||||||
|
full_restore = True
|
||||||
for archive_filename in name_list:
|
for archive_filename in name_list:
|
||||||
|
try:
|
||||||
archive.extract(archive_filename, target_path)
|
archive.extract(archive_filename, target_path)
|
||||||
CuraApplication.getInstance().processEvents()
|
|
||||||
except (PermissionError, EnvironmentError):
|
except (PermissionError, EnvironmentError):
|
||||||
Logger.logException("e", "Unable to extract the backup due to permission or file system errors.")
|
Logger.logException("e", f"Unable to extract the file {archive_filename} from the backup due to permission or file system errors.")
|
||||||
return False
|
failed_files.append(archive_filename)
|
||||||
return True
|
full_restore = False
|
||||||
|
CuraApplication.getInstance().processEvents()
|
||||||
|
return full_restore, failed_files
|
||||||
|
|
||||||
def _obfuscate(self) -> Dict[str, str]:
|
def _obfuscate(self) -> Dict[str, str]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user