Skip to content

Commit a0d2edb

Browse files
committed
add user as suffix to mix_pubsub and mix_lock paths
1 parent 695acad commit a0d2edb

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

lib/mix/lib/mix/sync/lock.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ defmodule Mix.Sync.Lock do
9797
opts = Keyword.validate!(opts, [:on_taken])
9898

9999
hash = key |> :erlang.md5() |> Base.url_encode64(padding: false)
100-
base_path = Path.join([System.tmp_dir!(), "mix_lock"])
101-
init_base_path(base_path)
102-
path = Path.join([base_path, hash])
100+
path = Path.join(base_path(), hash)
103101

104102
pdict_key = {__MODULE__, path}
105103
has_lock? = Process.get(pdict_key, false)
@@ -121,10 +119,11 @@ defmodule Mix.Sync.Lock do
121119
end
122120
end
123121

124-
defp init_base_path(path) do
122+
defp base_path do
123+
user = System.get_env("USER", "default")
124+
path = Path.join([System.tmp_dir!(), "mix_pubsub_#{Base.url_encode64(user, padding: false)}"])
125125
File.mkdir_p!(path)
126-
# ensure other users can write to the directory
127-
_ = File.chmod(path, 0o777)
126+
path
128127
end
129128

130129
defp lock_disabled?(), do: System.get_env("MIX_OS_CONCURRENCY_LOCK") in ~w(0 false)

lib/mix/lib/mix/sync/pubsub.ex

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ defmodule Mix.Sync.PubSub do
127127
@impl true
128128
def init({}) do
129129
state = %{port: nil, hash_to_pids: %{}}
130-
init_base_path()
131130
{:ok, state}
132131
end
133132

@@ -274,19 +273,15 @@ defmodule Mix.Sync.PubSub do
274273
defp hash(key), do: :erlang.md5(key)
275274

276275
defp base_path do
277-
Path.join(System.tmp_dir!(), "mix_pubsub")
276+
user = System.get_env("USER", "default")
277+
path = Path.join([System.tmp_dir!(), "mix_lock_#{Base.url_encode64(user, padding: false)}"])
278+
File.mkdir_p!(path)
279+
path
278280
end
279281

280282
defp path(hash) do
281283
hash = Base.url_encode64(hash, padding: false)
282-
Path.join([base_path(), hash])
283-
end
284-
285-
defp init_base_path do
286-
path = base_path()
287-
File.mkdir_p!(path)
288-
# ensure other users can write to the directory
289-
_ = File.chmod(path, 0o777)
284+
Path.join(base_path(), hash)
290285
end
291286

292287
defp recv(socket, size, timeout \\ :infinity) do

0 commit comments

Comments
 (0)