Skip to content

Commit 03439f4

Browse files
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. (cherry picked from commit 0c8935c)
1 parent 7653a0a commit 03439f4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ui/opensnitch/utils/xdg.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def __init__(self):
6363
self.systemAutostart = '/usr' + self.systemAutostart
6464
self.userAutostart = os.path.join(xdg_config_home, 'autostart', desktopFile)
6565

66+
def _copyfile(self, src, dst):
67+
"""copy file (.desktop) to dst. Ignore exception if src and dst are equal"""
68+
try:
69+
shutil.copyfile(src, dst)
70+
except shutil.SameFileError:
71+
pass
72+
6673
def createUserDir(self):
6774
if not os.path.isdir(xdg_config_home):
6875
os.makedirs(xdg_config_home, 0o700)
@@ -88,10 +95,10 @@ def enable(self, mode=True):
8895
if os.path.isfile(self.systemAutostart) and os.path.isfile(self.userAutostart):
8996
os.remove(self.userAutostart)
9097
elif os.path.isfile(self.systemDesktop):
91-
shutil.copyfile(self.systemDesktop, self.userAutostart)
98+
self._copyfile(self.systemDesktop, self.userAutostart)
9299
else:
93100
if os.path.isfile(self.systemAutostart):
94-
shutil.copyfile(self.systemAutostart, self.userAutostart)
101+
self._copyfile(self.systemAutostart, self.userAutostart)
95102
with open(self.userAutostart, 'a') as f:
96103
f.write('Hidden=true\n')
97104
elif os.path.isfile(self.userAutostart):

0 commit comments

Comments
 (0)