From 7a0e72bfa9975f5e918f49e2cffedb53a11e2b99 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 28 Sep 2018 20:09:45 -0400 Subject: [PATCH] env_get_pwd_slash to return L"/" if $PWD is empty or missing Prior to this change, env_get_pwd_slash() would try to infer the PWD from getcwd() if $PWD were missing. But this results env_get_pwd_slash() doing something radically different than $PWD, and also is a lot of code for a scenario that cannot be reliably reproduced. Just return "/" in this case. --- src/env.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 8967369ec..b3adf9a0e 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -697,37 +697,13 @@ void env_set_read_limit() { } wcstring env_get_pwd_slash() { + // Return "/" if PWD is missing. + // See https://github.com/fish-shell/fish-shell/issues/5080 auto pwd_var = env_get(L"PWD"); wcstring pwd; if (!pwd_var.missing_or_empty()) { pwd = pwd_var->as_string(); } - else { - // Not sure how we can end up here, but it's possible. - // See https://github.com/fish-shell/fish-shell/issues/5080 - // Perhaps it can happen on some platforms if the path is too long? - std::vector path; - bool cwd_success = false; - for (int i = 1; !cwd_success && i <= 10; ++i) { - path.resize(PATH_MAX * i); - if (getcwd(&path[0], PATH_MAX * i) == nullptr) { - if (errno == ERANGE) { - // buffer is not big enough, try again (up to a point) - continue; - } - debug(1, "getcwd() failed with errno %d", errno); - // . but with a trailing slash, because that's what this function does - return L"./"; - } - cwd_success = true; - } - if (!cwd_success) { - debug(1, "getcwd() path too long!"); - return L"./"; - } - pwd = str2wcstring(path.data()); - } - if (!string_suffixes_string(L"/", pwd)) { pwd.push_back(L'/'); }