mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-15 08:25:25 +00:00
Fix order of precedence for options
Fixes #2066 and #2166 Enforce the following order of precedence for options, first match wins: 1. Command line arguments 2. .GNUstepDefaults 3. /etc/sogo/{debconf,sogo}.conf 4. SOGoDefaults.plist
This commit is contained in:
@@ -79,7 +79,7 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
|
|||||||
if ([fm fileExistsAtPath: filename])
|
if ([fm fileExistsAtPath: filename])
|
||||||
{
|
{
|
||||||
fileAttrs = [fm fileAttributesAtPath: filename
|
fileAttrs = [fm fileAttributesAtPath: filename
|
||||||
traverseLink: YES];
|
traverseLink: YES];
|
||||||
if (![fileAttrs objectForKey: @"NSFileSize"])
|
if (![fileAttrs objectForKey: @"NSFileSize"])
|
||||||
{
|
{
|
||||||
[logger errorWithFormat:
|
[logger errorWithFormat:
|
||||||
@@ -111,6 +111,25 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
|
|||||||
|
|
||||||
+ (void) prepareUserDefaults
|
+ (void) prepareUserDefaults
|
||||||
{
|
{
|
||||||
|
/* Load settings from configuration files and
|
||||||
|
* enforce the following order of precedence.
|
||||||
|
* First match wins
|
||||||
|
* 1. Command line arguments
|
||||||
|
* 2. .GNUstepDefaults
|
||||||
|
* 3. /etc/sogo/{debconf,sogo}.conf
|
||||||
|
* 4. SOGoDefaults.plist
|
||||||
|
*
|
||||||
|
* The default standardUserDefaults search list is as follows:
|
||||||
|
* GSPrimaryDomain
|
||||||
|
* NSArgumentDomain (command line arguments)
|
||||||
|
* applicationDomain (sogod)
|
||||||
|
* NSGlobalDomain
|
||||||
|
* GSConfigDomain
|
||||||
|
* (languages)
|
||||||
|
* NSRegistrationDomain
|
||||||
|
*/
|
||||||
|
|
||||||
|
NSDictionary *sogodDomain;
|
||||||
NSUserDefaults *ud;
|
NSUserDefaults *ud;
|
||||||
SOGoStartupLogger *logger;
|
SOGoStartupLogger *logger;
|
||||||
NSBundle *bundle;
|
NSBundle *bundle;
|
||||||
@@ -121,24 +140,32 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
|
|||||||
|
|
||||||
logger = [SOGoStartupLogger sharedLogger];
|
logger = [SOGoStartupLogger sharedLogger];
|
||||||
|
|
||||||
/* we load the configuration from the standard user default files */
|
/* Load the configuration from the standard user default files
|
||||||
|
* into the 'sogod' domain */
|
||||||
ud = [NSUserDefaults standardUserDefaults];
|
ud = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
/* reregister defaults from domain "sogod" into default domain, for
|
/* Populate NSRegistrationDomain with default values from SOGoDefaults.plist */
|
||||||
non-sogod processes */
|
|
||||||
[ud addSuiteNamed: @"sogod"];
|
|
||||||
|
|
||||||
/* we populate the configuration with the values from SOGoDefaults.plist */
|
|
||||||
bundle = [NSBundle bundleForClass: self];
|
bundle = [NSBundle bundleForClass: self];
|
||||||
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
|
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
|
||||||
if (filename)
|
if (filename)
|
||||||
_injectConfigurationFromFile (ud, filename, logger);
|
_injectConfigurationFromFile (ud, filename, logger);
|
||||||
|
|
||||||
/* fill the possibly missing values with the configuration stored
|
/* Fill/Override NSRegistrationDomain values with configuration stored
|
||||||
in "/etc" */
|
* in "/etc" */
|
||||||
for (count = 0; count < sizeof(confFiles)/sizeof(confFiles[0]); count++)
|
for (count = 0; count < sizeof(confFiles)/sizeof(confFiles[0]); count++)
|
||||||
_injectConfigurationFromFile (ud, confFiles[count], logger);
|
_injectConfigurationFromFile (ud, confFiles[count], logger);
|
||||||
|
|
||||||
|
/* This dance is required to let other appplications (sogo-tool) use
|
||||||
|
* options from the sogod domain while preserving the order of precedence
|
||||||
|
* - remove the 'sogod' domain from the user defaults search list
|
||||||
|
* - register the content of the sogod domain into the NSRegistrationDomain
|
||||||
|
* Thereby overriding values from the config files loaded above
|
||||||
|
*/
|
||||||
|
[ud removeSuiteNamed: @"sogod"];
|
||||||
|
sogodDomain = [ud persistentDomainForName: @"sogod"];
|
||||||
|
if ([sogodDomain count])
|
||||||
|
[ud registerDefaults: sogodDomain];
|
||||||
|
|
||||||
/* issue a warning if WOApplicationRedirectURL is used */
|
/* issue a warning if WOApplicationRedirectURL is used */
|
||||||
redirectURL = [ud stringForKey: @"WOApplicationRedirectURL"];
|
redirectURL = [ud stringForKey: @"WOApplicationRedirectURL"];
|
||||||
if (redirectURL)
|
if (redirectURL)
|
||||||
|
|||||||
Reference in New Issue
Block a user