@@ -319,8 +319,15 @@ defmodule Mix.Local.Installer do
319
319
"""
320
320
@ spec fetch ( tuple , ( atom -> any ) , ( atom -> any ) ) :: any
321
321
def fetch ( dep_spec , in_fetcher \\ & in_fetcher / 1 , in_package ) do
322
- with_tmp_dir ( fn tmp_path ->
322
+ tmp_path = tmp_path ( )
323
+ previous_env = Mix . env ( )
324
+ deps_path = System . get_env ( "MIX_DEPS_PATH" )
325
+ code_path = :code . get_path ( )
326
+
327
+ try do
323
328
File . mkdir_p! ( tmp_path )
329
+ System . delete_env ( "MIX_DEPS_PATH" )
330
+ Mix . env ( :prod )
324
331
325
332
File . write! ( Path . join ( tmp_path , "mix.exs" ) , """
326
333
defmodule Mix.Local.Installer.MixProject do
@@ -336,34 +343,36 @@ defmodule Mix.Local.Installer do
336
343
end
337
344
""" )
338
345
339
- with_reset_prod_env ( fn ->
340
- Mix.ProjectStack . on_clean_slate ( fn ->
341
- tmp_path =
342
- Mix.Project . in_project ( :mix_local_installer , tmp_path , [ ] , fn mix_exs ->
343
- in_fetcher . ( mix_exs )
346
+ Mix.ProjectStack . on_clean_slate ( fn ->
347
+ tmp_path =
348
+ Mix.Project . in_project ( :mix_local_installer , tmp_path , [ ] , fn mix_exs ->
349
+ in_fetcher . ( mix_exs )
344
350
345
- # The tmp_dir may have symlinks in it, so we properly resolve
346
- # the directory before customizing deps_path and lockfile.
347
- File . cwd! ( )
348
- end )
351
+ # The tmp_dir may have symlinks in it, so we properly resolve
352
+ # the directory before customizing deps_path and lockfile.
353
+ File . cwd! ( )
354
+ end )
349
355
350
- { package_name , package_path } = package_name_path ( dep_spec , tmp_path )
356
+ { package_name , package_path } = package_name_path ( dep_spec , tmp_path )
351
357
352
- post_config = [
353
- deps_path: Path . join ( tmp_path , "deps" ) ,
354
- lockfile: Path . join ( tmp_path , "mix.lock" )
355
- ]
358
+ post_config = [
359
+ deps_path: Path . join ( tmp_path , "deps" ) ,
360
+ lockfile: Path . join ( tmp_path , "mix.lock" )
361
+ ]
356
362
357
- Mix.Project . in_project ( package_name , package_path , post_config , fn mix_exs ->
358
- in_fetcher . ( mix_exs )
359
- in_package . ( mix_exs )
360
- end )
363
+ Mix.Project . in_project ( package_name , package_path , post_config , fn mix_exs ->
364
+ in_fetcher . ( mix_exs )
365
+ in_package . ( mix_exs )
361
366
end )
362
367
end )
363
- end )
364
- after
365
- :code . purge ( Mix.Local.Installer.Fetcher )
366
- :code . delete ( Mix.Local.Installer.Fetcher )
368
+ after
369
+ File . rm_rf ( tmp_path )
370
+ Mix . env ( previous_env )
371
+ deps_path && System . put_env ( "MIX_DEPS_PATH" , deps_path )
372
+ :code . set_path ( code_path )
373
+ :code . purge ( Mix.Local.Installer.Fetcher )
374
+ :code . delete ( Mix.Local.Installer.Fetcher )
375
+ end
367
376
end
368
377
369
378
defp package_name_path ( dep_spec , tmp_path ) do
@@ -388,28 +397,8 @@ defmodule Mix.Local.Installer do
388
397
Mix.Task . run ( "deps.get" , [ "--only" , Atom . to_string ( Mix . env ( ) ) ] )
389
398
end
390
399
391
- defp with_tmp_dir ( fun ) do
400
+ defp tmp_path do
392
401
unique = :crypto . strong_rand_bytes ( 4 ) |> Base . url_encode64 ( padding: false )
393
- tmp_path = Path . join ( System . tmp_dir! ( ) , "mix-local-installer-fetcher-" <> unique )
394
-
395
- try do
396
- fun . ( tmp_path )
397
- after
398
- File . rm_rf ( tmp_path )
399
- end
400
- end
401
-
402
- defp with_reset_prod_env ( fun ) do
403
- previous_env = Mix . env ( )
404
- deps_path = System . get_env ( "MIX_DEPS_PATH" )
405
-
406
- try do
407
- System . delete_env ( "MIX_DEPS_PATH" )
408
- Mix . env ( :prod )
409
- fun . ( )
410
- after
411
- Mix . env ( previous_env )
412
- deps_path && System . put_env ( "MIX_DEPS_PATH" , deps_path )
413
- end
402
+ Path . join ( System . tmp_dir! ( ) , "mix-local-installer-fetcher-" <> unique )
414
403
end
415
404
end
0 commit comments