[Xfce4-commits] [apps/xfce4-panel-profiles] 149/162: Fix (LP: #1765565): Don't crash on corrupted panel configs.

noreply at xfce.org noreply at xfce.org
Fri Jul 13 13:10:48 CEST 2018


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-panel-profiles.

commit 86704fd04f68303971ce4845646be0fd163e7616
Author: Alistair Buxton <a.j.buxton at gmail.com>
Date:   Fri Apr 20 02:57:32 2018 +0100

    Fix (LP: #1765565): Don't crash on corrupted panel configs.
    
    1. Fix the problem directly:
    
    Catch the exception if the .desktop file is missing and return false.
    This will remove launchers with missing .desktop (not just the binary).
    
    2. Fix the problem more generally:
    
    Ignore orphan plugin configurations. This is a plugin configuration
    section which is not refered to by any panel and therefore is not used.
    Some old versions of xfce4-panel seem to create these, but I can't
    reproduce with the latest version.
    
    These orphans are completely ignored by the panel. Xfpanel-switch also
    ignores them, unless they are launchers with missing .desktop files.
    The second part of this patch cleans them out anyway.
---
 xfpanel-switch/panelconfig.py | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/xfpanel-switch/panelconfig.py b/xfpanel-switch/panelconfig.py
index 0153ae5..609034e 100644
--- a/xfpanel-switch/panelconfig.py
+++ b/xfpanel-switch/panelconfig.py
@@ -61,6 +61,7 @@ class PanelConfig(object):
 
             pc.properties[pp] = pv
 
+        pc.remove_orphans()
         pc.find_desktops()
 
         pc.source = None
@@ -84,8 +85,35 @@ class PanelConfig(object):
 
         return pc
 
+    def remove_orphans(self):
+        plugin_ids = set()
+        rem_keys = []
+
+        for pp, pv in self.properties.items():
+            path = pp.split('/')
+            if len(path) == 4 and path[0] == '' and path[1] == 'panels' and \
+                    path[2].startswith('panel-') and path[3] == 'plugin-ids':
+                plugin_ids.update(pv)
+
+        for pp, pv in self.properties.items():
+            path = pp.split('/')
+            if len(path) == 3 and path[0] == '' and path[1] == 'plugins' and \
+                    path[2].startswith('plugin-'):
+                number = path[2].split('-')[1]
+                try:
+                    if int(number) not in plugin_ids:
+                        rem_keys.append('/plugins/plugin-' + number)
+                except ValueError:
+                    pass
+
+        self.remove_keys(rem_keys)
+
     def check_desktop(self, path):
-        bytes = self.get_desktop_source_file(path).read()
+        try:
+            bytes = self.get_desktop_source_file(path).read()
+        except FileNotFoundError:
+            # If the .desktop file does not exist at all return False
+            return False
 
         # Check if binary exists
         keyfile = GLib.KeyFile.new()
@@ -99,7 +127,7 @@ class PanelConfig(object):
         return False
 
     def find_desktops(self):
-        remove_keys = []
+        rem_keys = []
 
         for pp, pv in self.properties.items():
             path = pp.split('/')
@@ -114,11 +142,14 @@ class PanelConfig(object):
                         if self.check_desktop(desktop_path):
                             self.desktops.append(desktop_path)
                         else:
-                            remove_keys.append('/plugins/plugin-' + number)
+                            rem_keys.append('/plugins/plugin-' + number)
+
+        self.remove_keys(rem_keys)
 
+    def remove_keys(self, rem_keys):
         keys = list(self.properties.keys())
         for param in keys:
-            for bad_plugin in remove_keys:
+            for bad_plugin in rem_keys:
                 if param.startswith(bad_plugin):
                     self.properties.pop(param, None)
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list