mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-10 01:36:39 +02:00
Added support for loading system configs if there's no user config. (#914)
* Added support for loading system configs if there's no user config file supplied. Uses application defaults if corrupt. * Update documentation to indicate where config files can be stored & read from
This commit is contained in:
parent
203da2dfb8
commit
46c91bac6e
|
@ -238,7 +238,11 @@ Configuration is determined by three layers: the default values, values set in t
|
|||
|
||||
Most command line options have a respective configuration file setting.
|
||||
|
||||
If you want to change the defaults, you can copy and edit the included config file into your `~/.config/onedrive` directory:
|
||||
If you want to change the defaults, you can copy and edit the included config file into your configuration directory. Valid directories for the config file are:
|
||||
* `~/.config/onedrive`
|
||||
* `/etc/onedrive`
|
||||
|
||||
**Example:**
|
||||
```text
|
||||
mkdir -p ~/.config/onedrive
|
||||
cp ./config ~/.config/onedrive/config
|
||||
|
|
38
src/config.d
38
src/config.d
|
@ -19,10 +19,12 @@ final class Config
|
|||
public string syncListFilePath = "";
|
||||
public string homePath = "";
|
||||
public string configDirName = "";
|
||||
public string systemConfigDirName = "";
|
||||
public string configFileSyncDir = "";
|
||||
public string configFileSkipFile = "";
|
||||
public string configFileSkipDir = "";
|
||||
private string userConfigFilePath = "";
|
||||
private string systemConfigFilePath = "";
|
||||
// was the application just authorised - paste of response uri
|
||||
public bool applicationAuthorizeResponseUri = false;
|
||||
// hashmap for the values found in the user config file
|
||||
|
@ -122,6 +124,7 @@ final class Config
|
|||
|
||||
// Determine the correct configuration directory to use
|
||||
string configDirBase;
|
||||
string systemConfigDirBase;
|
||||
if (confdirOption != "") {
|
||||
// A CLI 'confdir' was passed in
|
||||
log.vdebug("configDirName: CLI override to set configDirName to: ", confdirOption);
|
||||
|
@ -141,6 +144,8 @@ final class Config
|
|||
// XDG_CONFIG_HOME does not exist on systems where X11 is not present - ie - headless systems / servers
|
||||
log.vdebug("configDirBase: WARNING - no XDG_CONFIG_HOME environment variable set");
|
||||
configDirBase = homePath ~ "/.config";
|
||||
// Also set up a path to pre-shipped shared configs (which can be overridden by supplying a config file in userspace)
|
||||
systemConfigDirBase = "/etc";
|
||||
}
|
||||
|
||||
// Output configDirBase calculation
|
||||
|
@ -149,12 +154,15 @@ final class Config
|
|||
log.vdebug("configDirName: Configuring application to use default config path");
|
||||
// configDirBase contains the correct path so we do not need to check for presence of '~'
|
||||
configDirName = configDirBase ~ "/onedrive";
|
||||
// systemConfigDirBase contains the correct path so we do not need to check for presence of '~'
|
||||
systemConfigDirName = systemConfigDirBase ~ "/onedrive";
|
||||
}
|
||||
|
||||
// Config directory options all determined
|
||||
// configDirName has a trailing /
|
||||
log.vlog("Using Config Dir: ", configDirName);
|
||||
if (!exists(configDirName)) mkdirRecurse(configDirName);
|
||||
// configDirName has a trailing /
|
||||
log.vlog("Using 'user' Config Dir: ", configDirName);
|
||||
log.vlog("Using 'system' Config Dir: ", systemConfigDirName);
|
||||
|
||||
// Update application set variables based on configDirName
|
||||
refreshTokenFilePath = buildNormalizedPath(configDirName ~ "/refresh_token");
|
||||
|
@ -164,6 +172,7 @@ final class Config
|
|||
uploadStateFilePath = buildNormalizedPath(configDirName ~ "/resume_upload");
|
||||
userConfigFilePath = buildNormalizedPath(configDirName ~ "/config");
|
||||
syncListFilePath = buildNormalizedPath(configDirName ~ "/sync_list");
|
||||
systemConfigFilePath = buildNormalizedPath(systemConfigDirName ~ "/config");
|
||||
|
||||
// Debug Output for application set variables based on configDirName
|
||||
log.vdebug("refreshTokenFilePath = ", refreshTokenFilePath);
|
||||
|
@ -173,17 +182,34 @@ final class Config
|
|||
log.vdebug("uploadStateFilePath = ", uploadStateFilePath);
|
||||
log.vdebug("userConfigFilePath = ", userConfigFilePath);
|
||||
log.vdebug("syncListFilePath = ", syncListFilePath);
|
||||
log.vdebug("systemConfigFilePath = ", systemConfigFilePath);
|
||||
}
|
||||
|
||||
bool initialize()
|
||||
{
|
||||
// Initialise the application
|
||||
if (!exists(userConfigFilePath)) {
|
||||
// configuration file does not exist
|
||||
log.vlog("No config file found, using application defaults");
|
||||
return true;
|
||||
// 'user' configuration file does not exist
|
||||
// Is there a system configuration file?
|
||||
if (!exists(systemConfigFilePath)) {
|
||||
// 'system' configuration file does not exist
|
||||
log.vlog("No user or system config file found, using application defaults");
|
||||
return true;
|
||||
} else {
|
||||
// 'system' configuration file exists
|
||||
// can we load the configuration file without error?
|
||||
if (load(systemConfigFilePath)) {
|
||||
// configuration file loaded without error
|
||||
log.log("System configuration file successfully loaded");
|
||||
return true;
|
||||
} else {
|
||||
// there was a problem loading the configuration file
|
||||
log.log("System configuration file has errors - please check your configuration");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// configuration file exists
|
||||
// 'user' configuration file exists
|
||||
// can we load the configuration file without error?
|
||||
if (load(userConfigFilePath)) {
|
||||
// configuration file loaded without error
|
||||
|
|
Loading…
Reference in a new issue