mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-12-22 09:59:48 +01:00
internal: fixes to config path handling
This commit is contained in:
parent
dbe5835573
commit
689b405d9d
2 changed files with 17 additions and 14 deletions
|
@ -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();
|
||||
|
@ -543,11 +536,20 @@ CParseResult CConfig::parse() {
|
|||
applyDefaultsToCat(*sc);
|
||||
}
|
||||
|
||||
// implies options.allowMissingConfig
|
||||
if (impl->path.empty())
|
||||
return CParseResult{};
|
||||
bool fileExists = std::filesystem::exists(impl->path);
|
||||
|
||||
CParseResult fileParseResult = parseFile(impl->path.c_str());
|
||||
// implies options.allowMissingConfig
|
||||
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(canonical.c_str());
|
||||
|
||||
return fileParseResult;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue