diff --git a/src/helpers/fs/FsUtils.cpp b/src/helpers/fs/FsUtils.cpp index b687ca7fc94..cd1b77bb785 100644 --- a/src/helpers/fs/FsUtils.cpp +++ b/src/helpers/fs/FsUtils.cpp @@ -2,7 +2,6 @@ #include "../../debug/log/Logger.hpp" #include -#include #include #include @@ -57,17 +56,14 @@ std::optional NFsUtils::getDataHome() { return hyprlandDataDir.string(); } -std::optional NFsUtils::readFileAsString(const std::string& path) { - std::error_code ec; - - if (!std::filesystem::exists(path, ec) || ec) - return std::nullopt; - - std::ifstream file(path); - if (!file.good()) +std::optional NFsUtils::readFileAsString(const std::filesystem::path& path) { + std::ifstream ifs(path); + if (!ifs.is_open()) { return std::nullopt; + } - return trim(std::string((std::istreambuf_iterator(file)), (std::istreambuf_iterator()))); + std::string data(std::istreambuf_iterator{ifs}, std::istreambuf_iterator{}); + return trim(data); } bool NFsUtils::writeToFile(const std::string& path, const std::string& content) { diff --git a/src/helpers/fs/FsUtils.hpp b/src/helpers/fs/FsUtils.hpp index bc3b3bf18e6..cfd49b7a94a 100644 --- a/src/helpers/fs/FsUtils.hpp +++ b/src/helpers/fs/FsUtils.hpp @@ -1,4 +1,6 @@ #pragma once + +#include #include #include @@ -6,7 +8,7 @@ namespace NFsUtils { // Returns the path to the hyprland directory in data home. std::optional getDataHome(); - std::optional readFileAsString(const std::string& path); + std::optional readFileAsString(const std::filesystem::path& path); // overwrites the file if exists bool writeToFile(const std::string& path, const std::string& content);