mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-11 10:16:39 +02:00
check config file keys for validity (#296)
* check config file keys for validity, use setValue instead of direct access * Update config.d Add 'drive_id' to be initialised, set to an empty string * exit application if there is a configuration file error * Issue #293 was caused by a spelling error in the configuration file. If the configuration file has errors, we should not load it or run using the application defaults as this may have undesirable consequences for users data * missed returning false on key issue * Missed this edit of the file
This commit is contained in:
parent
bbe672bff1
commit
025a3b2878
25
src/config.d
25
src/config.d
|
@ -24,7 +24,7 @@ final class Config
|
|||
syncListFilePath = configDirName ~ "/sync_list";
|
||||
}
|
||||
|
||||
void init()
|
||||
bool init()
|
||||
{
|
||||
// Default configuration directory
|
||||
setValue("sync_dir", "~/OneDrive");
|
||||
|
@ -39,10 +39,20 @@ final class Config
|
|||
setValue("monitor_interval", "45");
|
||||
// Configure the default logging directory to be /var/log/onedrive/
|
||||
setValue("log_dir", "/var/log/onedrive/");
|
||||
// Configure a default empty value for drive_id
|
||||
setValue("drive_id", "");
|
||||
|
||||
if (!load(userConfigFilePath)) {
|
||||
log.vlog("No config file found, using defaults");
|
||||
// What was the reason for failure?
|
||||
if (!exists(userConfigFilePath)) {
|
||||
log.vlog("No config file found, using application defaults");
|
||||
return true;
|
||||
} else {
|
||||
log.log("Configuration file has errors - please check your configuration");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string getValue(string key)
|
||||
|
@ -82,10 +92,17 @@ final class Config
|
|||
if (!c.empty) {
|
||||
c.popFront(); // skip the whole match
|
||||
string key = c.front.dup;
|
||||
c.popFront();
|
||||
values[key] = c.front.dup;
|
||||
auto p = key in values;
|
||||
if (p) {
|
||||
c.popFront();
|
||||
setValue(key, c.front.dup);
|
||||
} else {
|
||||
log.log("Unknown key in config file: ", key);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log.log("Malformed config line: ", line);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -155,7 +155,11 @@ int main(string[] args)
|
|||
log.vlog("Using Config Dir: ", configDirName);
|
||||
if (!exists(configDirName)) mkdirRecurse(configDirName);
|
||||
auto cfg = new config.Config(configDirName);
|
||||
cfg.init();
|
||||
if(!cfg.init()){
|
||||
// There was an error loading the configuration
|
||||
// Error message already printed
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Set the local path OneDrive root
|
||||
string syncDir;
|
||||
|
|
Loading…
Reference in a new issue