Chromium Code Reviews| Index: base/files/file_util_posix.cc |
| diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc |
| index ca1c5250b920d310e0be12acb2a73a5cede3bddc..91e613825de488f06ca0f6c516330fde320f0b36 100644 |
| --- a/base/files/file_util_posix.cc |
| +++ b/base/files/file_util_posix.cc |
| @@ -22,6 +22,7 @@ |
| #include <time.h> |
| #include <unistd.h> |
| +#include "base/environment.h" |
| #include "base/files/file_enumerator.h" |
| #include "base/files/file_path.h" |
| #include "base/files/scoped_file.h" |
| @@ -31,6 +32,7 @@ |
| #include "base/path_service.h" |
| #include "base/posix/eintr_wrapper.h" |
| #include "base/stl_util.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/sys_string_conversions.h" |
| @@ -455,6 +457,25 @@ bool SetPosixFilePermissions(const FilePath& path, |
| return true; |
| } |
| +bool ExecutableExistsInPath(const char* executable) { |
| + std::unique_ptr<base::Environment> env(base::Environment::Create()); |
|
Lei Zhang
2016/06/21 21:31:21
You can omit base:: in namespace base.
Tom (Use chromium acct)
2016/06/22 16:57:55
Done.
|
| + std::string path; |
| + if (!env->GetVar("PATH", &path)) { |
| + LOG(ERROR) << "No $PATH variable. Assuming no " << executable << "."; |
| + return false; |
| + } |
| + |
| + for (const base::StringPiece& cur_path : base::SplitStringPiece( |
| + path, ":", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
| + base::FilePath file(cur_path); |
| + int permissions; |
| + if (GetPosixFilePermissions(file.Append(executable), &permissions) && |
| + (permissions & FILE_PERMISSION_EXECUTE_BY_USER)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| #if !defined(OS_MACOSX) |
| // This is implemented in file_util_mac.mm for Mac. |
| bool GetTempDir(FilePath* path) { |