Skip to content

Commit 2e48d81

Browse files
author
José Valim
committed
Move printing out of copy_path, always create dir
Signed-off-by: José Valim <[email protected]>
1 parent e7ef3fc commit 2e48d81

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

lib/mix/lib/mix/tasks/archive.install.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ defmodule Mix.Tasks.Archive.Install do
5454
if opts[:force] || should_install?(src, previous) do
5555
remove_previous_versions(previous)
5656

57-
dest = Mix.Local.archives_path()
58-
archive = Path.join(dest, basename(src))
57+
archive = Path.join(Mix.Local.archives_path(), basename(src))
5958
check_file_exists(archive)
6059

61-
File.mkdir_p!(dest)
62-
Mix.Utils.copy_path!(src, archive, opts)
60+
if Mix.Utils.copy_path!(src, archive, opts) do
61+
Mix.shell.info [:green, "* creating ", :reset, Path.relative_to_cwd(archive)]
62+
end
6363

6464
true = Code.append_path(Mix.Archive.ebin(archive))
6565
else

lib/mix/lib/mix/tasks/local.rebar.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ defmodule Mix.Tasks.Local.Rebar do
3030

3131
defp do_install(path, opts) do
3232
local_rebar_path = Mix.Rebar.local_rebar_path
33-
File.mkdir_p! Path.dirname(local_rebar_path)
3433

35-
Mix.Utils.copy_path!(path, local_rebar_path, opts)
36-
:ok = :file.change_mode local_rebar_path, 0o755
34+
if Mix.Utils.copy_path!(path, local_rebar_path, opts) do
35+
:ok = :file.change_mode local_rebar_path, 0o755
36+
Mix.shell.info [:green, "* creating ", :reset, Path.relative_to_cwd(local_rebar_path)]
37+
end
38+
3739
true
3840
end
3941
end

lib/mix/lib/mix/utils.ex

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ defmodule Mix.Utils do
368368
def read_path!(path, opts \\ []) do
369369
cond do
370370
url?(path) && opts[:shell] ->
371-
read_shell(path, [])
371+
read_shell(path, nil)
372372
url?(path) ->
373-
read_httpc(path, [])
373+
read_httpc(path, nil)
374374
file?(path) ->
375375
read_file(path)
376376
true ->
@@ -395,23 +395,23 @@ defmodule Mix.Utils do
395395
396396
* `:force` - Forces overwriting target file without a shell prompt.
397397
"""
398-
def copy_path!(source, target, opts \\ []) do
398+
def copy_path!(source, target, opts \\ []) when is_binary(source) and is_binary(target) do
399399
if opts[:force] || overwriting?(target) do
400400
cond do
401401
url?(source) && opts[:shell] ->
402-
read_shell(source, file: target)
402+
read_shell(source, target)
403403
url?(source) ->
404-
read_httpc(source, file: target)
404+
read_httpc(source, target)
405405
file?(source) ->
406406
copy_file(source, target)
407407
true ->
408408
Mix.raise "Expected #{source} to be a url or a local file path"
409409
end
410410

411-
put_creating_file(target)
411+
true
412+
else
413+
false
412414
end
413-
414-
:ok
415415
end
416416

417417
@doc """
@@ -432,10 +432,11 @@ defmodule Mix.Utils do
432432
end
433433

434434
defp copy_file(source, target) do
435+
File.mkdir_p!(Path.dirname(target))
435436
File.cp!(source, target)
436437
end
437438

438-
defp read_httpc(path, opts) do
439+
defp read_httpc(path, target) do
439440
{:ok, _} = Application.ensure_all_started(:ssl)
440441
{:ok, _} = Application.ensure_all_started(:inets)
441442

@@ -452,9 +453,10 @@ defmodule Mix.Utils do
452453
if http_proxy, do: proxy(http_proxy)
453454
if https_proxy, do: proxy(https_proxy)
454455

455-
if out_path = opts[:file] do
456-
File.rm(out_path)
457-
req_opts = [stream: String.to_char_list(out_path)]
456+
if target do
457+
File.mkdir_p!(Path.dirname(target))
458+
File.rm(target)
459+
req_opts = [stream: String.to_char_list(target)]
458460
else
459461
req_opts = [body_format: :binary]
460462
end
@@ -490,10 +492,11 @@ defmodule Mix.Utils do
490492
end
491493
end
492494

493-
defp read_shell(path, opts) do
495+
defp read_shell(path, target) do
494496
filename = URI.parse(path).path |> Path.basename
495-
out_path = opts[:file] || Path.join(System.tmp_dir!, filename)
497+
out_path = target || Path.join(System.tmp_dir!, filename)
496498

499+
File.mkdir_p!(Path.dirname(out_path))
497500
File.rm(out_path)
498501

499502
status = cond do
@@ -511,9 +514,9 @@ defmodule Mix.Utils do
511514
1
512515
end
513516

514-
check_command!(status, path, opts[:file])
517+
check_command!(status, path, target)
515518

516-
unless opts[:file] do
519+
unless target do
517520
data = File.read!(out_path)
518521
File.rm!(out_path)
519522
data
@@ -534,10 +537,6 @@ defmodule Mix.Utils do
534537
match?({:win32, _}, :os.type)
535538
end
536539

537-
defp put_creating_file(path) do
538-
Mix.shell.info [:green, "* creating ", :reset, Path.relative_to_cwd(path)]
539-
end
540-
541540
defp file?(path) do
542541
File.regular?(path)
543542
end

0 commit comments

Comments
 (0)