persepolisdm / persepolis

Persepolis Download Manager is a GUI for aria2.
https://persepolisdm.github.io
GNU General Public License v3.0
6.13k stars 647 forks source link

Simplify obtaining user name when creating lock file #904

Open danfe opened 2 years ago

danfe commented 2 years ago

It currently dances around os.path.expanduser("~") which is needlessly cumbersome and error-prone. Consider using just os.getlogin() instead:

--- persepolis/scripts/persepolis.py.orig
+++ persepolis/scripts/persepolis.py
@@ -42,9 +42,6 @@ if os_type == 'Linux' or os_type == 'FreeBSD' or os_ty

 # initialization

-# find home address
-home_address = os.path.expanduser("~")
-
 # persepolis config_folder
 config_folder = determineConfigFolder()

@@ -58,10 +55,8 @@ global lock_file_validation

 if os_type != 'Windows':
     import fcntl
-    user_name_split = home_address.split('/')
-    user_name = user_name_split[2]
 # persepolis lock file
-    lock_file = '/tmp/persepolis_exec_' + user_name + '.lock'
+    lock_file = '/tmp/persepolis_exec_' + os.getlogin() + '.lock'

 # create lock file
     fp = open(lock_file, 'w')