Is a named binary installed and executable by the current process? Note that this is harder than it seems like it should be...
| 88 | // Is a named binary installed and executable by the current process? |
| 89 | // Note that this is harder than it seems like it should be... |
| 90 | bool IsBinaryInstalled(const string& binary_name) { |
| 91 | string path = ::getenv("PATH"); |
| 92 | for (const string& dir : str_util::Split(path, ':')) { |
| 93 | const string binary_path = io::JoinPath(dir, binary_name); |
| 94 | char absolute_path[PATH_MAX + 1]; |
| 95 | if (::realpath(binary_path.c_str(), absolute_path) == nullptr) { |
| 96 | continue; |
| 97 | } |
| 98 | struct stat statinfo; |
| 99 | int result = ::stat(absolute_path, &statinfo); |
| 100 | if (result < 0) { |
| 101 | continue; |
| 102 | } |
| 103 | if (!S_ISREG(statinfo.st_mode)) { |
| 104 | continue; |
| 105 | } |
| 106 | |
| 107 | // Is the current user able to execute the file? |
| 108 | if (statinfo.st_uid == ::geteuid() && statinfo.st_mode & S_IXUSR) { |
| 109 | return true; |
| 110 | } |
| 111 | // Is the current group able to execute the file? |
| 112 | if (statinfo.st_uid == ::getegid() && statinfo.st_mode & S_IXGRP) { |
| 113 | return true; |
| 114 | } |
| 115 | // Is anyone able to execute the file? |
| 116 | if (statinfo.st_mode & S_IXOTH) { |
| 117 | return true; |
| 118 | } |
| 119 | } |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | [[noreturn]] int ExecuteFfmpeg(const std::vector<string>& args) { |
| 124 | std::vector<char*> args_chars; |
no test coverage detected