Fix incorrectly nested configDir in X11 systems (Issue #181) (#182)

* Fix incorrectly nested configDir in X11 systems
This commit is contained in:
Marcus Ball 2018-09-20 15:45:06 -04:00 committed by abraunegg
parent 53cbc8ff5e
commit 3a4c71d7ee

View file

@ -10,10 +10,7 @@ int main(string[] args)
// Determine the users home directory. // Determine the users home directory.
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts // Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
string homePath = ""; string homePath = "";
if (environment.get("XDG_CONFIG_HOME") != ""){
homePath = environment.get("XDG_CONFIG_HOME");
} else {
// XDG_CONFIG_HOME does not exist on systems where X11 is not present - ie - headless systems / servers
// Check for HOME environment variable // Check for HOME environment variable
if (environment.get("HOME") != ""){ if (environment.get("HOME") != ""){
// Use HOME environment variable // Use HOME environment variable
@ -23,14 +20,22 @@ int main(string[] args)
// No shell is set or username - observed case when running as systemd service under CentOS 7.x // No shell is set or username - observed case when running as systemd service under CentOS 7.x
homePath = "/root"; homePath = "/root";
} else { } else {
// A shell & valid user is set, but no XDG_CONFIG_HOME or HOME set // A shell & valid user is set, but no HOME is set, use ~ which can be expanded
homePath = "~"; homePath = "~";
} }
} }
// Determine the base directory relative to which user specific configuration files should be stored.
string configDirBase = "";
if (environment.get("XDG_CONFIG_HOME") != ""){
configDirBase = environment.get("XDG_CONFIG_HOME");
} else {
// XDG_CONFIG_HOME does not exist on systems where X11 is not present - ie - headless systems / servers
configDirBase = homePath ~ "/.config";
} }
// configuration directory // configuration directory
string configDirName = homePath ~ "/.config/onedrive"; string configDirName = configDirBase ~ "/onedrive";
// only download remote changes // only download remote changes
bool downloadOnly; bool downloadOnly;
// override the sync directory // override the sync directory