Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/helpers/fs/FsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <algorithm>

#include <hyprutils/string/String.hpp>
#include <hyprutils/string/VarList.hpp>
#include <hyprutils/string/VarList2.hpp>
using namespace Hyprutils::String;

std::optional<std::string> NFsUtils::getDataHome() {
Expand Down Expand Up @@ -84,28 +85,24 @@
}

bool NFsUtils::executableExistsInPath(const std::string& exe) {
if (!getenv("PATH"))
const char* const path = std::getenv("PATH");
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
if (path == nullptr)
return false;

static CVarList paths(getenv("PATH"), 0, ':', true);
static CVarList2 paths(std::string{path}, 0, ':', true);

for (auto& p : paths) {
std::string path = p + std::string{"/"} + exe;
std::error_code ec;
if (!std::filesystem::exists(path, ec) || ec)
continue;

if (!std::filesystem::is_regular_file(path, ec) || ec)
continue;

auto stat = std::filesystem::status(path, ec);
if (ec)
continue;
std::filesystem::path fullPath;
return std::ranges::any_of(paths, [&](std::string_view dir) -> bool {
fullPath = dir;
fullPath /= exe;

auto perms = stat.permissions();
std::error_code ec;
auto status = std::filesystem::status(fullPath, ec);

return std::filesystem::perms::none != (perms & std::filesystem::perms::others_exec);
}
if (ec || !std::filesystem::is_regular_file(status)) {
Comment thread
vaxerski marked this conversation as resolved.
Outdated
return false;
}

return false;
return (status.permissions() & std::filesystem::perms::others_exec) != std::filesystem::perms::none;
});
}
Loading