@@ -368,9 +368,9 @@ defmodule Mix.Utils do
368
368
def read_path! ( path , opts \\ [ ] ) do
369
369
cond do
370
370
url? ( path ) && opts [ :shell ] ->
371
- read_shell ( path , [ ] )
371
+ read_shell ( path , nil )
372
372
url? ( path ) ->
373
- read_httpc ( path , [ ] )
373
+ read_httpc ( path , nil )
374
374
file? ( path ) ->
375
375
read_file ( path )
376
376
true ->
@@ -395,23 +395,23 @@ defmodule Mix.Utils do
395
395
396
396
* `:force` - Forces overwriting target file without a shell prompt.
397
397
"""
398
- def copy_path! ( source , target , opts \\ [ ] ) do
398
+ def copy_path! ( source , target , opts \\ [ ] ) when is_binary ( source ) and is_binary ( target ) do
399
399
if opts [ :force ] || overwriting? ( target ) do
400
400
cond do
401
401
url? ( source ) && opts [ :shell ] ->
402
- read_shell ( source , file: target )
402
+ read_shell ( source , target )
403
403
url? ( source ) ->
404
- read_httpc ( source , file: target )
404
+ read_httpc ( source , target )
405
405
file? ( source ) ->
406
406
copy_file ( source , target )
407
407
true ->
408
408
Mix . raise "Expected #{ source } to be a url or a local file path"
409
409
end
410
410
411
- put_creating_file ( target )
411
+ true
412
+ else
413
+ false
412
414
end
413
-
414
- :ok
415
415
end
416
416
417
417
@ doc """
@@ -432,10 +432,11 @@ defmodule Mix.Utils do
432
432
end
433
433
434
434
defp copy_file ( source , target ) do
435
+ File . mkdir_p! ( Path . dirname ( target ) )
435
436
File . cp! ( source , target )
436
437
end
437
438
438
- defp read_httpc ( path , opts ) do
439
+ defp read_httpc ( path , target ) do
439
440
{ :ok , _ } = Application . ensure_all_started ( :ssl )
440
441
{ :ok , _ } = Application . ensure_all_started ( :inets )
441
442
@@ -452,9 +453,10 @@ defmodule Mix.Utils do
452
453
if http_proxy , do: proxy ( http_proxy )
453
454
if https_proxy , do: proxy ( https_proxy )
454
455
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 ) ]
458
460
else
459
461
req_opts = [ body_format: :binary ]
460
462
end
@@ -490,10 +492,11 @@ defmodule Mix.Utils do
490
492
end
491
493
end
492
494
493
- defp read_shell ( path , opts ) do
495
+ defp read_shell ( path , target ) do
494
496
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 )
496
498
499
+ File . mkdir_p! ( Path . dirname ( out_path ) )
497
500
File . rm ( out_path )
498
501
499
502
status = cond do
@@ -511,9 +514,9 @@ defmodule Mix.Utils do
511
514
1
512
515
end
513
516
514
- check_command! ( status , path , opts [ :file ] )
517
+ check_command! ( status , path , target )
515
518
516
- unless opts [ :file ] do
519
+ unless target do
517
520
data = File . read! ( out_path )
518
521
File . rm! ( out_path )
519
522
data
@@ -534,10 +537,6 @@ defmodule Mix.Utils do
534
537
match? ( { :win32 , _ } , :os . type )
535
538
end
536
539
537
- defp put_creating_file ( path ) do
538
- Mix . shell . info [ :green , "* creating " , :reset , Path . relative_to_cwd ( path ) ]
539
- end
540
-
541
540
defp file? ( path ) do
542
541
File . regular? ( path )
543
542
end
0 commit comments