Merge pull request #9 from inverse-inc/fix/2066_options-precedence

Fix/2066 options precedence
This commit is contained in:
jraby
2013-01-31 18:42:09 -08:00
+41 -34
View File
@@ -62,24 +62,9 @@ BootstrapNSUserDefaults ()
if (handle)
{
SOGoNSUserDefaultsBootstrap = dlsym (handle,
"SOGoNSUserDefaultsBootstrap");
"SOGoNSUserDefaultsBootstrap");
if (SOGoNSUserDefaultsBootstrap)
SOGoNSUserDefaultsBootstrap ();
}
}
static void
_migrateSOGo09Configuration (NSUserDefaults *ud, NSObject *logger)
{
NSDictionary *domain;
domain = [ud persistentDomainForName: @"sogod-0.9"];
if ([domain count])
{
[logger logWithFormat: @"migrating user defaults from sogod-0.9"];
[ud setPersistentDomain: domain forName: @"sogod"];
[ud removePersistentDomainForName: @"sogod-0.9"];
[ud synchronize];
SOGoNSUserDefaultsBootstrap ();
}
}
@@ -94,14 +79,14 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
if ([fm fileExistsAtPath: filename])
{
fileAttrs = [fm fileAttributesAtPath: filename
traverseLink: YES];
traverseLink: YES];
if (![fileAttrs objectForKey: @"NSFileSize"])
{
[logger errorWithFormat:
@"Can't get file attributes from '%@'",
filename];
@"Can't get file attributes from '%@'",
filename];
exit(1);
}
}
if ([[fileAttrs objectForKey: @"NSFileSize"] intValue] == 0 )
{
[logger warnWithFormat:
@@ -126,6 +111,25 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
+ (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;
SOGoStartupLogger *logger;
NSBundle *bundle;
@@ -136,29 +140,32 @@ _injectConfigurationFromFile (NSUserDefaults *ud,
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];
/* if "sogod" does not exist, maybe "sogod-0.9" still exists from an old
configuration */
if (![[ud persistentDomainForName: @"sogod"] count])
_migrateSOGo09Configuration (ud, logger);
/* reregister defaults from domain "sogod" into default domain, for
non-sogod processes */
[ud addSuiteNamed: @"sogod"];
/* we populate the configuration with the values from SOGoDefaults.plist */
/* Populate NSRegistrationDomain with default values from SOGoDefaults.plist */
bundle = [NSBundle bundleForClass: self];
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
if (filename)
_injectConfigurationFromFile (ud, filename, logger);
/* fill the possibly missing values with the configuration stored
in "/etc" */
/* Fill/Override NSRegistrationDomain values with configuration stored
* in "/etc" */
for (count = 0; count < sizeof(confFiles)/sizeof(confFiles[0]); count++)
_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 */
redirectURL = [ud stringForKey: @"WOApplicationRedirectURL"];
if (redirectURL)