From 2d572eef7f5eed3dcfd4b7a4c97e9a4b1e17e745 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 28 May 2021 10:25:35 +0200 Subject: [PATCH 1/3] No longer include plugins in the backup Backups are synced with your account anyway. Backing up the plugins means that you quickly reach the limit of the max size (250mb) that the backups allow. CURA-8269 --- cura/Backups/Backup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cura/Backups/Backup.py b/cura/Backups/Backup.py index 85852e74f6..6f4a44d37e 100644 --- a/cura/Backups/Backup.py +++ b/cura/Backups/Backup.py @@ -28,6 +28,8 @@ class Backup: IGNORED_FILES = [r"cura\.log", r"plugins\.json", r"cache", r"__pycache__", r"\.qmlc", r"\.pyc"] """These files should be ignored when making a backup.""" + IGNORED_FOLDERS = [r"plugins"] + SECRETS_SETTINGS = ["general/ultimaker_auth_data"] """Secret preferences that need to obfuscated when making a backup of Cura""" @@ -74,8 +76,9 @@ class Backup: machine_count = max(len([s for s in files if "machine_instances/" in s]) - 1, 0) # If people delete their profiles but not their preferences, it can still make a backup, and report -1 profiles. Server crashes on this. material_count = max(len([s for s in files if "materials/" in s]) - 1, 0) profile_count = max(len([s for s in files if "quality_changes/" in s]) - 1, 0) - plugin_count = len([s for s in files if "plugin.json" in s]) - + # We don't store plugins anymore, since if you can make backups, you have an account (and the plugins are + # on the marketplace anyway) + plugin_count = 0 # Store the archive and metadata so the BackupManager can fetch them when needed. self.zip_file = buffer.getvalue() self.meta_data = { @@ -94,8 +97,7 @@ class Backup: :param root_path: The root directory to archive recursively. :return: The archive as bytes. """ - - ignore_string = re.compile("|".join(self.IGNORED_FILES)) + ignore_string = re.compile("|".join(self.IGNORED_FILES + self.IGNORED_FOLDERS)) try: archive = ZipFile(buffer, "w", ZIP_DEFLATED) for root, folders, files in os.walk(root_path): From cb2a7e1daa842ba70c40e88ee4d6d7fef29cdffb Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 1 Jun 2021 14:37:12 +0200 Subject: [PATCH 2/3] Remove plugins that weren't restored in the backup from the installed list CURA-8269 --- cura/Backups/BackupsManager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cura/Backups/BackupsManager.py b/cura/Backups/BackupsManager.py index fb758455c1..6d620b8d27 100644 --- a/cura/Backups/BackupsManager.py +++ b/cura/Backups/BackupsManager.py @@ -4,6 +4,7 @@ from typing import Dict, Optional, Tuple, TYPE_CHECKING from UM.Logger import Logger +from UM.Version import Version from cura.Backups.Backup import Backup if TYPE_CHECKING: @@ -52,6 +53,18 @@ class BackupsManager: backup = Backup(self._application, zip_file = zip_file, meta_data = meta_data) restored = backup.restore() + + package_manager = self._application.getPackageManager() + + # If the backup was made with Cura 4.10 (or higher), we no longer store plugins. + # Since the restored backup doesn't have those plugins anymore, we should remove it from the list + # of installed plugins. + if Version(meta_data.get("cura_release")) >= Version("4.10.0"): + for package_id in package_manager.getAllInstalledPackageIDs(): + package_data = package_manager.getInstalledPackageInfo(package_id) + if package_data.get("package_type") == "plugin" and not package_data.get("is_bundled"): + package_manager.removePackage(package_id) + if restored: # At this point, Cura will need to restart for the changes to take effect. # We don't want to store the data at this point as that would override the just-restored backup. From 4fc43c2b324c960abff641e15f9e7afabc0280ef Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 3 Jun 2021 09:25:59 +0200 Subject: [PATCH 3/3] Compare version-objects, not strings. This would've gone so wrong if we actually released 4.10 without this, since, as a string, 4.10 is 'smaller than' 4.6 (for example), because alphanumerical-order. done as part of CURA-8269 --- cura/Backups/Backup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cura/Backups/Backup.py b/cura/Backups/Backup.py index 6f4a44d37e..d9f1788744 100644 --- a/cura/Backups/Backup.py +++ b/cura/Backups/Backup.py @@ -14,6 +14,7 @@ from UM.Logger import Logger from UM.Message import Message from UM.Platform import Platform from UM.Resources import Resources +from UM.Version import Version if TYPE_CHECKING: from cura.CuraApplication import CuraApplication @@ -134,8 +135,8 @@ class Backup: "Tried to restore a Cura backup without having proper data or meta data.")) return False - current_version = self._application.getVersion() - version_to_restore = self.meta_data.get("cura_release", "master") + current_version = Version(self._application.getVersion()) + version_to_restore = Version(self.meta_data.get("cura_release", "master")) if current_version < version_to_restore: # Cannot restore version newer than current because settings might have changed.