@@ -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