Skip to content

Commit

Permalink
do smarter symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Feb 20, 2020
1 parent 9c6a780 commit f23637a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions jill/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils import latest_version
from .utils import DmgMounter, TarMounter
from .utils import Version
from .utils import color
from .utils import color, show_verbose
from .download import download_package

import os
Expand Down Expand Up @@ -122,16 +122,30 @@ def make_symlinks(src_bin, symlink_dir, version):
# symlink rules:
# 1. always symlink latest
# 2. only make new symlink if it's a newer version
# - julia --> latest stable X.Y.Z
# - julia-1 --> latest stable 1.Y.Z
# - julia-1.0 --> latest stable 1.0.Z
# - don't make symlink to patch level
if os.path.exists(linkpath) or os.path.islink(linkpath):
old_ver = get_exec_version(linkpath)
if Version(old_ver) > Version(version):
# it's always false if version == "latest"
if (os.path.islink(linkpath) and
os.readlink(linkpath) == src_bin):
# happens when installing a new patch version
continue
msg = f"{color.YELLOW}removing previous symlink"

old_ver = Version(get_exec_version(linkpath))
new_ver = Version(get_exec_version(src_bin))
if show_verbose():
print(f"old symlink version: {old_ver}")
print(f"new installation version: {new_ver}")
if old_ver > new_ver:
# if two versions are the same, use the new one
continue

msg = f"{color.YELLOW}remove old symlink"
msg += f" {linkname}{color.END}"
print(msg)
os.remove(linkpath)
print(f"{color.GREEN}make symlink {linkpath}{color.END}")
print(f"{color.GREEN}make new symlink {linkpath}{color.END}")
if current_system() == "windows":
with open(linkpath, 'w') as f:
# create a cmd file to mimic how we do symlinks in linux
Expand Down Expand Up @@ -319,7 +333,7 @@ def install_julia(version=None, *,
return False

overwrite = True if version == "latest" else False
print(f"{color.BOLD}----- Download Package -----{color.END}")
print(f"{color.BOLD}----- Download Julia -----{color.END}")
package_path = download_package(version, system, arch,
upstream=upstream,
overwrite=overwrite)
Expand Down

0 comments on commit f23637a

Please sign in to comment.