Copy wakatime-cli when symlink fails

This commit is contained in:
Alan Hamlett 2022-01-06 18:16:02 -08:00
parent 66f5f48f33
commit 7d2bd0b7c5
1 changed files with 15 additions and 13 deletions

View File

@ -908,22 +908,24 @@ def download(url, filePath):
raise raise
def is_symlink(path):
try:
return os.is_symlink(path)
except:
return False
def createSymlink(): def createSymlink():
link = os.path.join(RESOURCES_FOLDER, 'wakatime-cli')
if is_win: if is_win:
link = os.path.join(RESOURCES_FOLDER, 'wakatime-cli.exe') link = link + '.exe'
if os.path.exists(link): elif os.path.exists(link) and is_symlink(link):
try: return # don't re-create symlink on Unix-like platforms
os.remove(link)
except: try:
log(traceback.format_exc()) os.symlink(getCliLocation(), link)
except:
try: try:
shutil.copy2(getCliLocation(), link) shutil.copy2(getCliLocation(), link)
except: except:
log(traceback.format_exc()) log(traceback.format_exc())
else:
link = os.path.join(RESOURCES_FOLDER, 'wakatime-cli')
if not os.path.exists(link):
try:
os.symlink(getCliLocation(), link)
except:
pass