Move executable-check to C++

This was already apparently supposed to work, but didn't because we
just overrode errno again.

This now means that, if a correctly named candidate exists, we don't
start the command-not-found handler.

See #8804
This commit is contained in:
Fabian Homborg
2022-03-31 15:10:45 +02:00
parent 90d52ee669
commit f13979bfbb
5 changed files with 16 additions and 17 deletions

View File

@@ -87,6 +87,15 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path,
return true;
}
err = EACCES;
if (out_path) *out_path = std::move(next_path);
} else if (errno != ENOENT && err == ENOENT) {
// Keep the first *interesting* error and path around.
// ENOENT isn't interesting because not having a file is the normal case.
auto tmperr = errno;
// Ignore if the parent directory is already inaccessible.
if (access(wcs2string(wdirname(next_path)).c_str(), X_OK) != 0) continue;
err = tmperr;
if (out_path) *out_path = std::move(next_path);
}
}