util: use canonical first on paths passed via args

This commit is contained in:
Vaxry 2024-03-10 03:06:39 +00:00
parent b2cd693956
commit 03d38a4232

View file

@ -123,10 +123,12 @@ static Hyprlang::CParseResult parseOverride(const char* C, const char* V) {
return result; return result;
} }
static std::optional<std::string> createCursorThemeFromPath(const std::string& path, const std::string& out_ = {}) { static std::optional<std::string> createCursorThemeFromPath(const std::string& path_, const std::string& out_ = {}) {
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path_))
return "input path does not exist"; return "input path does not exist";
const std::string path = std::filesystem::canonical(path_);
const auto MANIFESTPATH = path + "/manifest.hl"; const auto MANIFESTPATH = path + "/manifest.hl";
if (!std::filesystem::exists(MANIFESTPATH)) if (!std::filesystem::exists(MANIFESTPATH))
return "manifest.hl is missing"; return "manifest.hl is missing";
@ -286,14 +288,16 @@ static std::string spawnSync(const std::string& cmd) {
return result; return result;
} }
static std::optional<std::string> extractXTheme(const std::string& xpath, const std::string& out_) { static std::optional<std::string> extractXTheme(const std::string& xpath_, const std::string& out_) {
if (!spawnSync("xcur2png --help").contains("xcursor")) if (!spawnSync("xcur2png --help").contains("xcursor"))
return "missing dependency: -x requires xcur2png."; return "missing dependency: -x requires xcur2png.";
if (!std::filesystem::exists(xpath) || !std::filesystem::exists(xpath + "/cursors")) if (!std::filesystem::exists(xpath_) || !std::filesystem::exists(xpath_ + "/cursors"))
return "input path does not exist or is not an xcursor theme"; return "input path does not exist or is not an xcursor theme";
const std::string xpath = std::filesystem::canonical(xpath_);
std::string out = (out_.empty() ? xpath.substr(0, xpath.find_last_of('/') + 1) : out_) + "/extracted_" + xpath.substr(xpath.find_last_of('/') + 1) + "/"; std::string out = (out_.empty() ? xpath.substr(0, xpath.find_last_of('/') + 1) : out_) + "/extracted_" + xpath.substr(xpath.find_last_of('/') + 1) + "/";
// create output fs structure // create output fs structure