Skip to content

Commit 18811ed

Browse files
committed
fix(config): address PR review feedback
- Use std::error_code for filesystem calls to avoid exceptions - Move getCurrentConfigPath() body from header to cpp file - Apply clang-format
1 parent dca6536 commit 18811ed

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/config/ConfigManager.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using namespace std::string_literals;
4141
// Forward declaration for the source handler
4242
static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALUE);
4343

44-
static std::string getMainConfigPath() {
44+
static std::string getMainConfigPath() {
4545
static const auto paths = Hyprutils::Path::findConfig("hyprpaper");
4646

4747
return paths.first.value_or("");
@@ -80,6 +80,10 @@ Hyprlang::CConfig* CConfigManager::hyprlang() {
8080
return &m_config;
8181
}
8282

83+
const std::string& CConfigManager::getCurrentConfigPath() const {
84+
return m_currentConfigPath;
85+
}
86+
8387
static std::expected<std::string, std::string> resolvePath(const std::string_view& sv) {
8488
std::error_code ec;
8589
const auto CAN = std::filesystem::canonical(sv, ec);
@@ -105,7 +109,7 @@ static std::expected<std::string, std::string> getPath(const std::string_view& s
105109
} else if (!std::filesystem::path(sv).is_absolute() && !basePath.empty()) {
106110
// Make relative paths relative to the base path's directory
107111
auto baseDir = std::filesystem::path(basePath).parent_path();
108-
path = (baseDir / sv).string();
112+
path = (baseDir / sv).string();
109113
}
110114

111115
return resolvePath(path);
@@ -184,7 +188,7 @@ std::vector<CConfigManager::SSetting> CConfigManager::getSettings() {
184188
static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALUE) {
185189
Hyprlang::CParseResult result;
186190

187-
const auto value = Hyprutils::String::trim(VALUE);
191+
const auto value = Hyprutils::String::trim(VALUE);
188192

189193
if (value.empty()) {
190194
result.setError("source= requires a file path");
@@ -203,14 +207,16 @@ static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALU
203207
g_logger->log(LOG_DEBUG, "source: including '{}'", PATH);
204208

205209
// Support glob patterns
206-
glob_t globResult;
210+
glob_t globResult;
207211
Hyprutils::Utils::CScopeGuard scopeGuard([&globResult]() { globfree(&globResult); });
208212

209-
int globStatus = glob(PATH.c_str(), GLOB_TILDE | GLOB_NOSORT, nullptr, &globResult);
213+
int globStatus = glob(PATH.c_str(), GLOB_TILDE | GLOB_NOSORT, nullptr, &globResult);
210214

211215
if (globStatus == GLOB_NOMATCH) {
212216
// No glob match - try as a literal path
213-
if (!std::filesystem::exists(PATH)) {
217+
std::error_code ec;
218+
const auto exists = std::filesystem::exists(PATH, ec);
219+
if (ec || !exists) {
214220
result.setError(std::format("source file '{}' not found", PATH).c_str());
215221
return result;
216222
}
@@ -233,7 +239,9 @@ static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALU
233239
for (size_t i = 0; i < globResult.gl_pathc; i++) {
234240
const std::string matchedPath = globResult.gl_pathv[i];
235241

236-
if (!std::filesystem::is_regular_file(matchedPath)) {
242+
std::error_code ec;
243+
const auto isFile = std::filesystem::is_regular_file(matchedPath, ec);
244+
if (ec || !isFile) {
237245
g_logger->log(LOG_WARN, "source: skipping non-regular file '{}'", matchedPath);
238246
continue;
239247
}

src/config/ConfigManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CConfigManager {
2727

2828
std::vector<SSetting> getSettings();
2929

30-
const std::string& getCurrentConfigPath() const { return m_currentConfigPath; }
30+
const std::string& getCurrentConfigPath() const;
3131

3232
private:
3333
Hyprlang::CConfig m_config;

0 commit comments

Comments
 (0)