Skip to content

Commit

Permalink
Explicitly open registry and clean pdict
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Mar 2, 2016
1 parent a895c38 commit b9c330d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/hex/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ defmodule Hex.Mix do
else: requests
end

@doc """
Prepare Mix dependencies for the format the resolver expects.
"""
@spec prepare_deps([Mix.Dep.t]) :: [dep]
def prepare_deps(deps) do
Enum.map(deps, fn %Mix.Dep{app: app, deps: deps, opts: opts} ->
Expand Down
7 changes: 7 additions & 0 deletions lib/hex/remote_converger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Hex.RemoteConverger do
def converge(deps, lock) do
Hex.start
Hex.Utils.ensure_registry!()
Hex.Registry.open!(Hex.Registry.ETS)
verify_lock(lock)

# We cannot use given lock here, because all deps that are being
Expand Down Expand Up @@ -43,16 +44,22 @@ defmodule Hex.RemoteConverger do
Hex.Shell.error message
Mix.raise "Hex dependency resolution failed, relax the version requirements or unlock dependencies"
end
after
Hex.Registry.pdict_clean
end

def deps(%Mix.Dep{app: app}, lock) do
Hex.Registry.open!(Hex.Registry.ETS)

case Map.fetch(lock, app) do
{:ok, {:hex, name, version}} ->
deps = get_deps(name, version)

_ ->
[]
end
after
Hex.Registry.pdict_clean
end

defp get_deps(name, version) do
Expand Down
8 changes: 8 additions & 0 deletions lib/hex/scm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ defmodule Hex.SCM do
end

def managers(opts) do
Hex.Registry.open!(Hex.Registry.ETS)

case opts[:lock] do
{:hex, name, version} ->
name = Atom.to_string(name)
Expand All @@ -67,9 +69,13 @@ defmodule Hex.SCM do
_ ->
[]
end
after
Hex.Registry.pdict_clean
end

def checkout(opts) do
Hex.Registry.open!(Hex.Registry.ETS)

{:hex, _name, version} = opts[:lock]
name = opts[:hex]
dest = opts[:dest]
Expand Down Expand Up @@ -100,6 +106,8 @@ defmodule Hex.SCM do
File.write!(Path.join(dest, ".hex"), manifest)

opts[:lock]
after
Hex.Registry.pdict_clean
end

def update(opts) do
Expand Down
3 changes: 3 additions & 0 deletions lib/mix/tasks/hex/outdated.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ defmodule Mix.Tasks.Hex.Outdated do
lock = Mix.Dep.Lock.read
deps = Mix.Dep.loaded([]) |> Enum.filter(& &1.scm == Hex.SCM)

# Re-open registry because loading deps cleans the process dict
Hex.Utils.ensure_registry!()

case args do
[app] ->
single(deps, lock, app, opts)
Expand Down

0 comments on commit b9c330d

Please sign in to comment.