From bfdb4e9d2cfc7890c5f194e670039fa76c391330 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 10 May 2024 15:09:50 +0200 Subject: Added tests --- file.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'file.cpp') diff --git a/file.cpp b/file.cpp index da00dff..3149f63 100644 --- a/file.cpp +++ b/file.cpp @@ -2,6 +2,10 @@ #include +#include + +#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 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& list) { + std::vector 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 {}; +} -- cgit v1.2.3