MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / IsBinaryInstalled

Function IsBinaryInstalled

tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc:90–121  ·  view source on GitHub ↗

Is a named binary installed and executable by the current process? Note that this is harder than it seems like it should be...

Source from the content-addressed store, hash-verified

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...
90bool 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;

Callers 2

ReadAudioFileFunction · 0.85
ReadVideoFileFunction · 0.85

Calls 4

c_strMethod · 0.80
statClass · 0.70
SplitFunction · 0.50
JoinPathFunction · 0.50

Tested by

no test coverage detected