fixup perm_type debacle

This commit is contained in:
GloriousEggroll 2025-04-13 16:10:19 -06:00
parent 601d494dcf
commit 6de6ea1bea
2 changed files with 56 additions and 33 deletions

View file

@ -2154,7 +2154,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
# Configure button based on permission type
btn.set_sensitive(False)
@ -2213,7 +2213,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
btn_box.pack_end(btn, False, False, 0)
@ -2280,7 +2280,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
# Configure button based on permission type
btn.set_sensitive(False)
@ -2339,7 +2339,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
btn_box.pack_end(btn, False, False, 0)
@ -2448,7 +2448,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
# Configure button based on permission type
btn.set_sensitive(False)
@ -2508,7 +2508,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, perm_type)
btn_box.pack_end(btn, False, False, 0)
@ -2652,7 +2652,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, "filesystems")
# Configure button based on permission type
btn.set_sensitive(False)
@ -2712,7 +2712,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_remove_path, app_id, app, path)
btn.connect("clicked", self._on_remove_path, app_id, app, path, "filesystems")
btn_box.pack_end(btn, False, False, 0)
@ -2731,7 +2731,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-add-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._on_add_path, app_id, app)
btn.connect("clicked", self._on_add_path, app_id, app, "filesystems")
hbox.pack_end(btn, False, True, 0)
listbox.add(row)
@ -2991,6 +2991,13 @@ class MainWindow(Gtk.Window):
"persistent",
self.system_mode
)
elif perm_type == "filesystems":
success, message = fp_turbo.remove_file_permissions(
app_id,
path,
"filesystems",
self.system_mode
)
else:
success, message = fp_turbo.remove_permission_value(
app_id,
@ -3039,6 +3046,13 @@ class MainWindow(Gtk.Window):
"persistent",
self.system_mode
)
elif perm_type == "filesystems":
success, message = fp_turbo.add_file_permissions(
app_id,
path,
"filesystems",
self.system_mode
)
else:
success, message = fp_turbo.add_permission_value(
app_id,
@ -3338,7 +3352,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._global_on_remove_path, path)
btn.connect("clicked", self._global_on_remove_path, path, perm_type)
btn_box.pack_end(btn, False, False, 0)
hbox.pack_end(btn_box, False, False, 0)
@ -3461,7 +3475,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-remove-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._global_on_remove_path, path)
btn.connect("clicked", self._global_on_remove_path, path, "filesystems")
btn_box.pack_end(btn, False, False, 0)
hbox.pack_end(btn_box, False, False, 0)
@ -3480,7 +3494,7 @@ class MainWindow(Gtk.Window):
add_rm_icon = "list-add-symbolic"
use_icon = Gio.Icon.new_for_string(add_rm_icon)
btn.set_image(Gtk.Image.new_from_gicon(use_icon, Gtk.IconSize.BUTTON))
btn.connect("clicked", self._global_on_add_path)
btn.connect("clicked", self._global_on_add_path, "filesystems")
hbox.pack_end(btn, False, True, 0)
listbox.add(row)
@ -3686,6 +3700,13 @@ class MainWindow(Gtk.Window):
True,
self.system_mode
)
elif perm_type == "filesystems":
success, message = fp_turbo.remove_file_permissions(
path,
"filesystems",
True,
self.system_mode
)
else:
success, message = fp_turbo.global_remove_permission_value(
perm_type,
@ -3734,6 +3755,13 @@ class MainWindow(Gtk.Window):
True,
self.system_mode
)
elif perm_type == "filesystems":
success, message = fp_turbo.global_add_file_permissions(
path,
"filesystems",
True,
self.system_mode
)
else:
success, message = fp_turbo.global_add_permission_value(
perm_type,

View file

@ -1266,33 +1266,31 @@ def add_file_permissions(app_id: str, path: str, perm_type=None, system=False) -
# Ensure path do not ends with a trailing slash
filesystem_path = path.rstrip('/')
# Validate absolute paths start with /
if filesystem_path.startswith('/'):
filesystem_path = '/' + filesystem_path.lstrip('/')
if not key_file.has_group("Context"):
key_file.set_string("Context", perm_type, "")
# Now get the keys
context_keys = key_file.get_keys("Context")
# Check if perm_type exists in the section
if perm_type not in str(context_keys):
# Create the key with an empty string
key_file.set_string("Context", perm_type, "")
# Get existing filesystem paths
existing_paths = key_file.get_string("Context", perm_type)
if existing_paths is None or existing_paths == "":
# If no filesystems entry exists, create it
# If no filesystems exist, set the exact path provided
key_file.set_string("Context", perm_type, filesystem_path)
else:
# Split existing paths and check if our path already exists
existing_paths_list = existing_paths.split(';')
# Normalize paths for comparison (remove trailing slashes, convert to absolute paths)
normalized_new_path = os.path.abspath(filesystem_path.rstrip('/'))
normalized_existing_paths = [os.path.abspath(p.rstrip('/')) for p in existing_paths_list]
# Only add if the path doesn't already exist
if normalized_new_path not in normalized_existing_paths:
# Add new path with proper separator
separator = ';' if existing_paths.endswith(';') else ';'
key_file.set_string("Context", perm_type,
existing_paths + filesystem_path + ";")
existing_paths + separator + filesystem_path)
# Write the modified metadata back
try:
@ -1709,34 +1707,31 @@ def global_add_file_permissions(path: str, perm_type=None, override=True, system
# Ensure path do not ends with a trailing slash
filesystem_path = path.rstrip('/')
# Validate absolute paths start with /
if filesystem_path.startswith('/'):
filesystem_path = '/' + filesystem_path.lstrip('/')
if not key_file.has_group("Context"):
key_file.set_string("Context", perm_type, "")
# Now get the keys
context_keys = key_file.get_keys("Context")
# Check if perm_type exists in the section
if perm_type not in str(context_keys):
# Create the key with an empty string
key_file.set_string("Context", perm_type, "")
# Get existing filesystem paths
existing_paths = key_file.get_string("Context", perm_type)
if existing_paths is None or existing_paths == "":
# If no filesystems entry exists, create it
# If no filesystems exist, set the exact path provided
key_file.set_string("Context", perm_type, filesystem_path)
else:
# Split existing paths and check if our path already exists
existing_paths_list = existing_paths.split(';')
# Normalize paths for comparison (remove trailing slashes, convert to absolute paths)
normalized_new_path = os.path.abspath(filesystem_path.rstrip('/'))
normalized_existing_paths = [os.path.abspath(p.rstrip('/')) for p in existing_paths_list]
# Only add if the path doesn't already exist
if normalized_new_path not in normalized_existing_paths:
# Add new path with proper separator
separator = ';' if existing_paths.endswith(';') else ';'
key_file.set_string("Context", perm_type,
existing_paths + filesystem_path + ";")
existing_paths + separator + filesystem_path)
# Write the modified metadata back
try: