drop multi version support

This commit is contained in:
Connor Rigby 2017-12-07 15:48:34 -08:00 committed by Connor Rigby
parent 3682a80ff7
commit e140d152d8
3 changed files with 13 additions and 26 deletions

View file

@ -130,23 +130,10 @@ defmodule Farmbot.Farmware do
def lookup(name, version \\ nil) do
dir = Farmbot.Farmware.Installer.install_root_path
with {:ok, all_installed} <- File.ls(dir),
true <- name in all_installed,
{:ok, versions} <- File.ls(Path.join(dir, name))
true <- name in all_installed
do
[newest | _] = Enum.sort(versions, fn(ver_a, ver_b) ->
case Version.compare(ver_a, ver_b) do
:eq -> true
:gt -> true
:lt -> false
end
end)
to_fetch = (version || newest) |> Version.parse!()
if "#{to_fetch}" in versions do
mani_path = Path.join(Farmbot.Farmware.Installer.install_path(name, to_fetch), "manifest.json")
File.read!(mani_path) |> Poison.decode! |> new()
else
{:error, :no_version}
end
mani_path = Path.join(Farmbot.Farmware.Installer.install_path(name), "manifest.json")
File.read!(mani_path) |> Poison.decode! |> new()
else
false -> {:error, :not_installed}
{:error, _} = err -> err

View file

@ -16,13 +16,12 @@ defmodule Farmbot.Farmware.Installer do
def install_root_path, do: @farmware_install_path
@doc "Where on the filesystem is this Farmware installed."
def install_path(name, %Version{} = fw_version) do
Path.join([@farmware_install_path, name, fw_version |> to_string])
def install_path(%Farmware{name: name, version: version}) do
install_path(name)
end
@doc "Where on the filesystem is this Farmware installed."
def install_path(%Farmware{name: name, version: version}) do
install_path(name, version)
def install_path(name) when is_binary(name) do
Path.join([@farmware_install_path, name])
end
@doc "Add a repository to the database."
@ -131,7 +130,7 @@ defmodule Farmbot.Farmware.Installer do
# sets up directories or returns already_installed.
defp check_directory(fw_name, %Version{} = fw_version) do
Logger.info 3, "Checking directories for #{fw_name} - #{fw_version}"
install_path = install_path(fw_name, fw_version)
install_path = install_path(fw_name)
manifest_path = Path.join(install_path, "manifest.json")
if File.exists?(manifest_path) do
{:error, {fw_name, fw_version, :already_installed}}

View file

@ -13,9 +13,8 @@ defmodule Farmbot.Farmware.Runtime do
def execute(%Farmware{} = farmware) do
Logger.busy(2, "Beginning execution of #{inspect(farmware)}")
fw_path = Installer.install_path(farmware) |> Path.absname("#{:code.priv_dir(:farmbot)}/..")
with {:ok, cwd} <- File.cwd(),
:ok <- File.cd(fw_path),
cwd = File.cwd!()
with :ok <- File.cd(fw_path),
env <- build_env(farmware) do
exec = farmware.executable
@ -43,7 +42,9 @@ defmodule Farmbot.Farmware.Runtime do
)
)
else
{:error, err} -> raise RuntimeError, state: nil, message: err
{:error, err} ->
File.cd(cwd)
raise RuntimeError, state: nil, message: err
end
|> do_cleanup()
end