aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/path.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-05-04 15:19:47 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-05-04 15:32:04 -0700
commit79f342b954a6f47ee3f1277a899066a654e7c330 (patch)
treea9386ce1e108a5c046276e4266e0129404fc4ea0 /src/path.cpp
parent527e5f52ba5a097a24490065fea23b4627032e4c (diff)
lint cleanup: eliminate "redundant" errors
This removes some pointless parentheses but the primary focus is removing redundancies like unnecessary "else" clauses.
Diffstat (limited to 'src/path.cpp')
-rw-r--r--src/path.cpp125
1 files changed, 60 insertions, 65 deletions
diff --git a/src/path.cpp b/src/path.cpp
index d80ffadf..b5ee0790 100644
--- a/src/path.cpp
+++ b/src/path.cpp
@@ -22,71 +22,66 @@
static bool path_get_path_core(const wcstring &cmd, wcstring *out_path,
const env_var_t &bin_path_var) {
int err = ENOENT;
-
debug(3, L"path_get_path( '%ls' )", cmd.c_str());
// If the command has a slash, it must be a full path.
if (cmd.find(L'/') != wcstring::npos) {
- if (waccess(cmd, X_OK) == 0) {
- struct stat buff;
- if (wstat(cmd, &buff)) {
- return false;
- }
+ if (waccess(cmd, X_OK) != 0) {
+ return false;
+ }
- if (S_ISREG(buff.st_mode)) {
- if (out_path) out_path->assign(cmd);
- return true;
- } else {
- errno = EACCES;
- return false;
- }
- } else {
+ struct stat buff;
+ if (wstat(cmd, &buff)) {
return false;
}
+ if (S_ISREG(buff.st_mode)) {
+ if (out_path) out_path->assign(cmd);
+ return true;
+ }
+ errno = EACCES;
+ return false;
+ }
+ wcstring bin_path;
+ if (!bin_path_var.missing()) {
+ bin_path = bin_path_var;
} else {
- wcstring bin_path;
- if (!bin_path_var.missing()) {
- bin_path = bin_path_var;
+ if (contains(PREFIX L"/bin", L"/bin", L"/usr/bin")) {
+ bin_path = L"/bin" ARRAY_SEP_STR L"/usr/bin";
} else {
- if (contains(PREFIX L"/bin", L"/bin", L"/usr/bin")) {
- bin_path = L"/bin" ARRAY_SEP_STR L"/usr/bin";
- } else {
- bin_path = L"/bin" ARRAY_SEP_STR L"/usr/bin" ARRAY_SEP_STR PREFIX L"/bin";
- }
+ bin_path = L"/bin" ARRAY_SEP_STR L"/usr/bin" ARRAY_SEP_STR PREFIX L"/bin";
}
+ }
- wcstring nxt_path;
- wcstokenizer tokenizer(bin_path, ARRAY_SEP_STR);
- while (tokenizer.next(nxt_path)) {
- if (nxt_path.empty()) continue;
- append_path_component(nxt_path, cmd);
- if (waccess(nxt_path, X_OK) == 0) {
- struct stat buff;
- if (wstat(nxt_path, &buff) == -1) {
- if (errno != EACCES) {
- wperror(L"stat");
- }
- continue;
+ wcstring nxt_path;
+ wcstokenizer tokenizer(bin_path, ARRAY_SEP_STR);
+ while (tokenizer.next(nxt_path)) {
+ if (nxt_path.empty()) continue;
+ append_path_component(nxt_path, cmd);
+ if (waccess(nxt_path, X_OK) == 0) {
+ struct stat buff;
+ if (wstat(nxt_path, &buff) == -1) {
+ if (errno != EACCES) {
+ wperror(L"stat");
}
- if (S_ISREG(buff.st_mode)) {
- if (out_path) out_path->swap(nxt_path);
- return true;
+ continue;
+ }
+ if (S_ISREG(buff.st_mode)) {
+ if (out_path) out_path->swap(nxt_path);
+ return true;
+ }
+ err = EACCES;
+ } else {
+ switch (errno) {
+ case ENOENT:
+ case ENAMETOOLONG:
+ case EACCES:
+ case ENOTDIR: {
+ break;
}
- err = EACCES;
-
- } else {
- switch (errno) {
- case ENOENT:
- case ENAMETOOLONG:
- case EACCES:
- case ENOTDIR: {
- break;
- }
- default: {
- debug(1, MISSING_COMMAND_ERR_MSG, nxt_path.c_str());
- wperror(L"access");
- }
+ default: {
+ debug(1, MISSING_COMMAND_ERR_MSG, nxt_path.c_str());
+ wperror(L"access");
}
}
}
@@ -208,23 +203,23 @@ wcstring path_apply_working_directory(const wcstring &path, const wcstring &work
if (!prepend_wd) {
// No need to prepend the wd, so just return the path we were given.
return path;
- } else {
- // Remove up to one "./".
- wcstring path_component = path;
- if (string_prefixes_string(L"./", path_component)) {
- path_component.erase(0, 2);
- }
+ }
- // Removing leading /s.
- while (string_prefixes_string(L"/", path_component)) {
- path_component.erase(0, 1);
- }
+ // Remove up to one "./".
+ wcstring path_component = path;
+ if (string_prefixes_string(L"./", path_component)) {
+ path_component.erase(0, 2);
+ }
- // Construct and return a new path.
- wcstring new_path = working_directory;
- append_path_component(new_path, path_component);
- return new_path;
+ // Removing leading /s.
+ while (string_prefixes_string(L"/", path_component)) {
+ path_component.erase(0, 1);
}
+
+ // Construct and return a new path.
+ wcstring new_path = working_directory;
+ append_path_component(new_path, path_component);
+ return new_path;
}
static wcstring path_create_config() {