diff options
author | Mike Binns <TheFirstAvenger@users.noreply.github.com> | 2019-05-08 05:05:03 -0400 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2019-05-08 11:05:03 +0200 |
commit | 0bede3b9712cd499b233e6a80afb8a9f10589904 (patch) | |
tree | 466cc1c708080c6b1adb420593b68e69ef4308cf | |
parent | 2bce89045e5a56f006219967b5c947c6ac675c85 (diff) | |
download | elixir-0bede3b9712cd499b233e6a80afb8a9f10589904.tar.gz |
Improved archive.uninstall to find any version of specified file (#9025)
Added logic to search for `archive-name-*` if `archive-name` is not found when running `mix archive.uninstall archive-name`.
For example, `mix archive.uninstall ironman` will find `ironman-0.4.2` archive.
Still checks for exact match first, so only modifies cases where legacy would report "no archives found".
-rw-r--r-- | lib/mix/lib/mix/local/installer.ex | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/mix/lib/mix/local/installer.ex b/lib/mix/lib/mix/local/installer.ex index 729aacc26..3562a95be 100644 --- a/lib/mix/lib/mix/local/installer.ex +++ b/lib/mix/lib/mix/local/installer.ex @@ -241,19 +241,24 @@ defmodule Mix.Local.Installer do {opts, argv} = OptionParser.parse!(argv, switches: switches) if name = List.first(argv) do - path = Path.join(root, name) + found = + cond do + File.exists?(Path.join(root, name)) -> Path.join(root, name) + matching = matching_package(root, name) -> matching + true -> nil + end cond do - not File.exists?(path) -> - Mix.shell().error("Could not find a local artifact named #{inspect(name)}. We found:") - Mix.Task.rerun(listing) - nil + found && should_uninstall?(found, opts) -> + File.rm_rf!(found) + found - should_uninstall?(path, opts) -> - File.rm_rf!(path) - path + found -> + nil true -> + Mix.shell().error("Could not find a local artifact named #{inspect(name)}. We found:") + Mix.Task.rerun(listing) nil end else @@ -261,6 +266,10 @@ defmodule Mix.Local.Installer do end end + defp matching_package(root, name) do + [root, name <> "-*"] |> Path.join() |> Path.wildcard() |> List.first() + end + defp should_uninstall?(path, opts) do opts[:force] || Mix.shell().yes?("Are you sure you want to uninstall #{path}?") end |