environment vars on Windows should be case-insensitive #29334
Description
Disclaimer: I don't personally use Windows and I inferred this behavior only through appveyor. So maybe I'm missing some points here.
Anyway, how do you update PATH
to be used for setenv(command::Cmd, env)
on Windows? For example, if I do
env_var = copy(ENV)
env_var["PATH"] = "some_new_path" * ';' * env_var["PATH"]
setenv(command::Cmd, env_var)
it doesn't work since the original PATH is in env_var["Path"]
not env_var["PATH"]
. I had to implement something like this (JuliaPy/Conda.jl#121 (comment)):
env_var = copy(ENV)
all_keys = collect(keys(env_var))
ikey = findfirst(x -> uppercase(x) == "PATH", all_keys)
has_key = ikey !== nothing
path_key = has_key ? all_keys[ikey] : "PATH"
if has_key
env_var[path_key] = extra_path * path_sep * env_var[path_key]
else
env_var[path_key] = extra_path
end
I tried empty!(ENV); merge!(ENV, env_var)
but apparently empty!(ENV)
is not implemented (at least on Linux). Also, it would have emitted bunch of syscalls so maybe not a good idea in the first place.
So, I thought maybe Base
needs to have a case-insensitive (in-memory) dictionary and copy(ENV)
on Windows should return it. It also facilitates cross-platform testing.
cc: @stevengj