Skip to content

Commit

Permalink
Handle bad cases when creating myst shim.
Browse files Browse the repository at this point in the history
If a `myst` file already exists in the specified shims location, `setup` now determines whether that file is a proper shim or needs to be replaced. To avoid inappropriately messing with users' systems, `setup` will abort and prompt the user to remove the file manually and then re-run `setup`.
  • Loading branch information
faultyserver committed Apr 2, 2018
1 parent ae82574 commit fc3f14e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/commands/setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@ class MTENV

# Create mtenv-controlled shims for the Myst binary.
puts "Linking shims to #{shims_location}"
myst_path = File.join(shims_location, "myst")
File.symlink(File.expand_path("~/.mtenv/shims/myst"), myst_path)
myst_shim_path = File.expand_path("~/.mtenv/shims/myst")
myst_install_path = File.join(shims_location, "myst")
case
when File.symlink?(myst_install_path)
existing_path = File.real_path(myst_install_path)
if existing_path != myst_shim_path
STDERR.puts "`myst` already exists in #{shims_location} and points to #{existing_path}"
STDERR.puts "Remove it and re-run this setup to allow `mtenv` to install a new shim."
exit(1)
end
when File.exists?(myst_install_path)
STDERR.puts "`myst` already exists in #{shims_location} as a plain file."
STDERR.puts "Remove it and re-run this setup to allow `mtenv` to install a new shim."
exit(1)
else
File.symlink(myst_shim_path, myst_install_path)
end
end

puts "\nmtenv setup finished successfully."
Expand Down

0 comments on commit fc3f14e

Please sign in to comment.