Skip to content

Commit

Permalink
internal: fixes to config path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Feb 12, 2024
1 parent dbe5835 commit 689b405
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@ static std::string removeBeginEndSpacesTabs(std::string str) {
}

CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
impl = new CConfigImpl;
try {
impl->path = std::filesystem::canonical(path);
} catch (std::exception& e) {
if (!options.allowMissingConfig)
throw "Couldn't open file. File does not exist";
}
impl = new CConfigImpl;
impl->path = path;

if (!std::filesystem::exists(impl->path)) {
if (!options.allowMissingConfig)
throw "File does not exist";

impl->path = "";
}

impl->envVariables.clear();
Expand Down Expand Up @@ -543,11 +536,20 @@ CParseResult CConfig::parse() {
applyDefaultsToCat(*sc);
}

bool fileExists = std::filesystem::exists(impl->path);

// implies options.allowMissingConfig
if (impl->path.empty())
if (impl->configOptions.allowMissingConfig && !fileExists)
return CParseResult{};
else if (!fileExists) {
CParseResult res;
res.setError("Config file is missing");
return res;
}

std::string canonical = std::filesystem::canonical(impl->path);

CParseResult fileParseResult = parseFile(impl->path.c_str());
CParseResult fileParseResult = parseFile(canonical.c_str());

return fileParseResult;
}
Expand Down
3 changes: 2 additions & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct SSpecialCategory {

class CConfigImpl {
public:
std::string path = "";
std::string path = "";
std::string originalPath = "";

std::unordered_map<std::string, Hyprlang::CConfigValue> values;
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
Expand Down

0 comments on commit 689b405

Please sign in to comment.