File tree Expand file tree Collapse file tree 3 files changed +35
-9
lines changed Expand file tree Collapse file tree 3 files changed +35
-9
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,6 @@ defmodule Mix.Sync.Lock do
72
72
@ probe_data "mixlock"
73
73
@ probe_data_size byte_size ( @ probe_data )
74
74
@ probe_timeout_ms 5_000
75
- @ version 2
76
75
77
76
@ typedoc """
78
77
Options for `with_lock/3`.
@@ -132,12 +131,7 @@ defmodule Mix.Sync.Lock do
132
131
133
132
defp base_path do
134
133
# We include user in the dir to avoid permission conflicts across users
135
- user = System . get_env ( "USER" , "default" )
136
-
137
- Path . join (
138
- System . tmp_dir! ( ) ,
139
- "mix_lock_#{ @ version } _#{ Base . url_encode64 ( user , padding: false ) } "
140
- )
134
+ Path . join ( System . tmp_dir! ( ) , "mix_lock_user#{ Mix.Utils . detect_user_id! ( ) } " )
141
135
end
142
136
143
137
defp lock_disabled? ( ) , do: System . get_env ( "MIX_OS_CONCURRENCY_LOCK" ) in ~w( 0 false)
Original file line number Diff line number Diff line change @@ -282,8 +282,7 @@ defmodule Mix.Sync.PubSub do
282
282
283
283
defp base_path do
284
284
# We include user in the dir to avoid permission conflicts across users
285
- user = System . get_env ( "USER" , "default" )
286
- Path . join ( System . tmp_dir! ( ) , "mix_pubsub_#{ Base . url_encode64 ( user , padding: false ) } " )
285
+ Path . join ( System . tmp_dir! ( ) , "mix_pubsub_user#{ Mix.Utils . detect_user_id! ( ) } " )
287
286
end
288
287
289
288
defp recv ( socket , size , timeout \\ :infinity ) do
Original file line number Diff line number Diff line change @@ -874,4 +874,37 @@ defmodule Mix.Utils do
874
874
875
875
[ proxy_auth: { user , pass } ]
876
876
end
877
+
878
+ @ doc """
879
+ Returns the user id of the currently running process.
880
+
881
+ The user id is obtained by creating a temporary file and checking
882
+ it's UID. Note that the UID may be `nil` on non-Unix systems.
883
+ """
884
+ def detect_user_id! ( ) do
885
+ case Mix.State . fetch ( :user_id ) do
886
+ { :ok , uid } ->
887
+ uid
888
+
889
+ :error ->
890
+ dir = System . tmp_dir! ( )
891
+ File . mkdir_p! ( dir )
892
+ rand = :crypto . strong_rand_bytes ( 3 ) |> Base . url_encode64 ( )
893
+ path = Path . join ( dir , "mix_user_check_#{ System . os_time ( ) } _#{ rand } " )
894
+
895
+ uid =
896
+ try do
897
+ File . touch! ( path )
898
+ File . stat! ( path )
899
+ else
900
+ % { uid: :undefined } -> nil
901
+ % { uid: uid } -> uid
902
+ after
903
+ File . rm ( path )
904
+ end
905
+
906
+ Mix.State . put ( :user_id , uid )
907
+ uid
908
+ end
909
+ end
877
910
end
You can’t perform that action at this time.
0 commit comments