[Bf-blender-cvs] [b1b0e56a72a] master: Fix T59065: Blender default keyset is deletable by user!

Sebastian Parborg noreply at git.blender.org
Wed Oct 30 19:22:35 CET 2019


Commit: b1b0e56a72abf843ddc86288db6db7f3ec4be9aa
Author: Sebastian Parborg
Date:   Wed Oct 30 19:16:53 2019 +0100
Branches: master
https://developer.blender.org/rBb1b0e56a72abf843ddc86288db6db7f3ec4be9aa

Fix T59065: Blender default keyset is deletable by user!

Previously, you could delete presets that were part of the blender
default install. Now we check if the preset file resides in the bundled
file paths. If so, prevent deletion of the preset.

Reviewed By: Campbell

Differential Revision: http://developer.blender.org/D4522

===================================================================

M	release/scripts/modules/bpy/utils/__init__.py
M	release/scripts/startup/bl_operators/presets.py

===================================================================

diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 04aaa7bd69d..879275619ce 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -456,6 +456,27 @@ def preset_paths(subdir):
 
     return dirs
 
+def is_path_builtin(path):
+    """
+    Returns True if the path in question in one of the built in paths used by blender.
+
+    :arg path: Path you want to check if it is in the built in settings directory
+    """
+    search_path = _os.path.abspath(path)
+    user_path = resource_path('USER')
+
+    for res in ('SYSTEM', 'LOCAL'):
+        parent_path = resource_path(res)
+        if not parent_path or parent_path == user_path:
+            # Make sure that the current path is not empty string and that it is
+            # not the same as the user config path. IE "~/.config/blender" on linux
+            # This can happen on portable installs.
+            continue
+
+        if _os.path.samefile(_os.path.commonpath([parent_path]), _os.path.commonpath([parent_path, path])):
+            return True
+
+    return False
 
 def smpte_from_seconds(time, fps=None, fps_base=None):
     """
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 661a7bd4aea..235f92bd360 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -29,6 +29,8 @@ from bpy.props import (
     StringProperty,
 )
 
+from bpy.utils import is_path_builtin
+
 # For preset popover menu
 WindowManager.preset_name = StringProperty(
     name="Preset Name",
@@ -190,6 +192,11 @@ class AddPresetBase:
             if not filepath:
                 return {'CANCELLED'}
 
+            # Do not remove bundled presets
+            if is_path_builtin(filepath):
+                self.report({'WARNING'}, "You can't remove the default presets")
+                return {'CANCELLED'}
+
             try:
                 if hasattr(self, "remove"):
                     self.remove(context, filepath)



More information about the Bf-blender-cvs mailing list