diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-10 15:09:50 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-10 15:09:50 +0200 |
commit | bfdb4e9d2cfc7890c5f194e670039fa76c391330 (patch) | |
tree | 2584a736ed6f2827c39420882555a154d7b5d570 /file.cpp | |
parent | 6086ec079a31276c81decdd7b5b5daaafdeb58ca (diff) |
Added tests
Diffstat (limited to 'file.cpp')
-rw-r--r-- | file.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -2,6 +2,10 @@ #include <unordered_set> +#include <libreichwein/stringhelper.h> + +#include "env.h" + namespace fs = std::filesystem; const fs::path YMakefile{"YMakefile"}; @@ -29,3 +33,31 @@ std::filesystem::path simplified_path(const std::filesystem::path& p) } return p; } + +bool is_executable(const std::string& file) { + std::vector<std::string> paths {Reichwein::Stringhelper::split(env_value("PATH"), ":")}; + + for (const auto& i: paths) { + fs::path path{i + "/" + file}; + if (fs::exists(path) && (fs::status(path).permissions() & std::filesystem::perms::others_exec) != std::filesystem::perms::none) { + return true; + } + } + + return false; +} + +std::string find_executable(const std::vector<std::string>& list) { + std::vector<std::string> paths {Reichwein::Stringhelper::split(env_value("PATH"), ":")}; + + for (const auto& i: list) { + for (const auto& j: paths) { + fs::path path{j + "/" + i}; + if (fs::exists(path) && (fs::status(path).permissions() & std::filesystem::perms::others_exec) != std::filesystem::perms::none) { + return i; + } + } + } + + return {}; +} |