mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-11-17 02:25:59 +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
|
@ -31,18 +31,11 @@ static std::string removeBeginEndSpacesTabs(std::string str) {
|
||||||
|
|
||||||
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
||||||
impl = new CConfigImpl;
|
impl = new CConfigImpl;
|
||||||
try {
|
impl->path = path;
|
||||||
impl->path = std::filesystem::canonical(path);
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
if (!options.allowMissingConfig)
|
|
||||||
throw "Couldn't open file. File does not exist";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::filesystem::exists(impl->path)) {
|
if (!std::filesystem::exists(impl->path)) {
|
||||||
if (!options.allowMissingConfig)
|
if (!options.allowMissingConfig)
|
||||||
throw "File does not exist";
|
throw "File does not exist";
|
||||||
|
|
||||||
impl->path = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl->envVariables.clear();
|
impl->envVariables.clear();
|
||||||
|
@ -543,11 +536,20 @@ CParseResult CConfig::parse() {
|
||||||
applyDefaultsToCat(*sc);
|
applyDefaultsToCat(*sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// implies options.allowMissingConfig
|
bool fileExists = std::filesystem::exists(impl->path);
|
||||||
if (impl->path.empty())
|
|
||||||
return CParseResult{};
|
|
||||||
|
|
||||||
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;
|
return fileParseResult;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ struct SSpecialCategory {
|
||||||
class CConfigImpl {
|
class CConfigImpl {
|
||||||
public:
|
public:
|
||||||
std::string path = "";
|
std::string path = "";
|
||||||
|
std::string originalPath = "";
|
||||||
|
|
||||||
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
||||||
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
||||||
|
|
Loading…
Reference in a new issue