[Feature #19244] Windows: Prefer USERPROFILE over HOMEPATH on startup as well

This commit is contained in:
Lars Kanis 2023-10-27 03:16:18 +02:00 коммит произвёл GitHub
Родитель 77d7ac7c06
Коммит 9a618b95cd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 50 добавлений и 13 удалений

Просмотреть файл

@ -578,6 +578,40 @@ class TestDir < Test::Unit::TestCase
ENV.delete('USERPROFILE')
assert_equal("C:/ruby/homepath", Dir.home)
end
def test_home_at_startup_windows
env = {'HOME' => "C:\\ruby\\home"}
args = [env]
assert_separately(args, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_equal("C:/ruby/home", Dir.home)
end;
env['USERPROFILE'] = "C:\\ruby\\userprofile"
assert_separately(args, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_equal("C:/ruby/home", Dir.home)
end;
env['HOME'] = nil
assert_separately(args, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_equal("C:/ruby/userprofile", Dir.home)
end;
env['HOMEDRIVE'] = "C:"
env['HOMEPATH'] = "\\ruby\\homepath"
assert_separately(args, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_equal("C:/ruby/userprofile", Dir.home)
end;
env['USERPROFILE'] = nil
assert_separately(args, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_equal("C:/ruby/homepath", Dir.home)
end;
end
end
def test_home

Просмотреть файл

@ -622,21 +622,24 @@ init_env(void)
if (!GetEnvironmentVariableW(L"HOME", env, numberof(env))) {
f = FALSE;
if (GetEnvironmentVariableW(L"HOMEDRIVE", env, numberof(env)))
len = lstrlenW(env);
else
len = 0;
if (GetEnvironmentVariableW(L"HOMEPATH", env + len, numberof(env) - len) || len) {
if (GetEnvironmentVariableW(L"USERPROFILE", env, numberof(env))) {
f = TRUE;
}
else if (GetEnvironmentVariableW(L"USERPROFILE", env, numberof(env))) {
f = TRUE;
}
else if (get_special_folder(CSIDL_PROFILE, env, numberof(env))) {
f = TRUE;
}
else if (get_special_folder(CSIDL_PERSONAL, env, numberof(env))) {
f = TRUE;
else {
if (GetEnvironmentVariableW(L"HOMEDRIVE", env, numberof(env)))
len = lstrlenW(env);
else
len = 0;
if (GetEnvironmentVariableW(L"HOMEPATH", env + len, numberof(env) - len) || len) {
f = TRUE;
}
else if (get_special_folder(CSIDL_PROFILE, env, numberof(env))) {
f = TRUE;
}
else if (get_special_folder(CSIDL_PERSONAL, env, numberof(env))) {
f = TRUE;
}
}
if (f) {
regulate_path(env);