Skip to content

Commit

Permalink
ui, prefs: ignore SameFile error when enabling autostart
Browse files Browse the repository at this point in the history
When clicking [x] Autostart the GUI upon login, ignore the exception if
src and dst (opensnitch_ui.desktop) are the same file.

(cherry picked from commit 0c8935c)
  • Loading branch information
gustavo-iniguez-goya committed Jun 13, 2024
1 parent 7653a0a commit 03439f4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ui/opensnitch/utils/xdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def __init__(self):
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)
Expand All @@ -88,10 +95,10 @@ def enable(self, mode=True):
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):
Expand Down

0 comments on commit 03439f4

Please sign in to comment.