From 0c8935c6e8519f95a496b5878e68fe18b9bb48d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Sat, 18 May 2024 10:33:16 +0200 Subject: [PATCH] ui, prefs: ignore SameFile error when enabling autostart When clicking [x] Autostart the GUI upon login, ignore the exception if src and dst (opensnitch_ui.desktop) are the same file. --- ui/opensnitch/utils/xdg.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/opensnitch/utils/xdg.py b/ui/opensnitch/utils/xdg.py index 2b336d9f..6158f373 100644 --- a/ui/opensnitch/utils/xdg.py +++ b/ui/opensnitch/utils/xdg.py @@ -63,6 +63,13 @@ class Autostart(): self.systemAutostart = '/usr' + self.systemAutostart self.userAutostart = os.path.join(xdg_config_home, 'autostart', desktopFile) + def _copyfile(self, src, dst): + """copy file (.desktop) to dst. Ignore exception if src and dst are equal""" + try: + shutil.copyfile(src, dst) + except shutil.SameFileError: + pass + def createUserDir(self): if not os.path.isdir(xdg_config_home): os.makedirs(xdg_config_home, 0o700) @@ -88,10 +95,10 @@ class Autostart(): if os.path.isfile(self.systemAutostart) and os.path.isfile(self.userAutostart): os.remove(self.userAutostart) elif os.path.isfile(self.systemDesktop): - shutil.copyfile(self.systemDesktop, self.userAutostart) + self._copyfile(self.systemDesktop, self.userAutostart) else: if os.path.isfile(self.systemAutostart): - shutil.copyfile(self.systemAutostart, self.userAutostart) + self._copyfile(self.systemAutostart, self.userAutostart) with open(self.userAutostart, 'a') as f: f.write('Hidden=true\n') elif os.path.isfile(self.userAutostart):