Remove some unnecessary env_var_t usage

This commit is contained in:
ridiculousfish 2018-09-30 18:20:59 -04:00
parent 6147e9ee0d
commit bd7fea55c4
2 changed files with 15 additions and 14 deletions

View file

@ -727,30 +727,29 @@ static void expand_home_directory(wcstring &input) {
size_t tail_idx;
wcstring username = get_home_directory_name(input, &tail_idx);
maybe_t<env_var_t> home;
maybe_t<wcstring> home;
if (username.empty()) {
// Current users home directory.
home = env_get(L"HOME");
if (home.missing_or_empty()) {
auto home_var = env_get(L"HOME");
if (home_var.missing_or_empty()) {
input.clear();
return;
}
home = home_var->as_string();
tail_idx = 1;
} else {
// Some other users home directory.
// Some other user's home directory.
std::string name_cstr = wcs2string(username);
struct passwd userinfo;
struct passwd *result;
char buf[8192];
int retval = getpwnam_r(name_cstr.c_str(), &userinfo, buf, sizeof(buf), &result);
if (!retval && result) {
home = env_var_t(L"HOME", str2wcstring(userinfo.pw_dir));
home = str2wcstring(userinfo.pw_dir);
}
}
maybe_t<wcstring> realhome;
if (home) realhome = wrealpath(home->as_string());
maybe_t<wcstring> realhome = (home ? wrealpath(*home) : none());
if (realhome) {
input.replace(input.begin(), input.begin() + tail_idx, *realhome);
} else {

View file

@ -180,12 +180,14 @@ bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd,
paths.push_back(path);
} else {
// Respect CDPATH.
auto cdpaths = env_vars.get(L"CDPATH");
if (cdpaths.missing_or_empty()) cdpaths = env_var_t(L"CDPATH", L".");
std::vector<wcstring> cdpathsv;
cdpaths->to_list(cdpathsv);
for (auto next_path : cdpathsv) {
wcstring_list_t cdpathsv;
if (auto cdpaths = env_vars.get(L"CDPATH")) {
cdpathsv = cdpaths->as_list();
}
if (cdpathsv.empty()) {
cdpathsv.push_back(L".");
}
for (wcstring next_path : cdpathsv) {
if (next_path.empty()) next_path = L".";
if (next_path == L"." && wd != NULL) {
// next_path is just '.', and we have a working directory, so use the wd instead.