Add GlobalDefaults directory support.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31922 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2011-01-21 15:19:40 +00:00
parent 307d0ea1a1
commit ade4f3e9eb
4 changed files with 130 additions and 86 deletions

View file

@ -1,3 +1,13 @@
2011-01-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPathUtilities.m: Add support for GlobalDefaults directory
* Source/NSUserDefaults.m: Document GlobalDefaults directory
* Documentation/Base.gsdoc: Document GlobalDefaults directory
Implement suggestion by David Chisnall.
New GlobalDefaults directory support ... if there are .plist files
in this subdirectory, merge them in before merging in the contents of the GlobalDefaults.plist file.
Deprecate use of the old GNUSTEP_EXTRA config file entry.
2011-01-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPropertyList.m: Fix to cope with NSXMLParser reporting

View file

@ -629,18 +629,22 @@ notice and this notice are preserved.
<p>
All the above values from the configuration file are made
available in the NSUserDefaults system at runtime, in the
GSConfigDomain (along with any defaults provided in the
GSConfigDomain (along with any defaults provided in property
lists in the GlobalDefaults subdirectory or in the
GlobalDefaults.plist file in the same directory as the
config file).<br />
In addition, the configuration file may contain the key
<em>GNUSTEP_EXTRA</em> with a value set to be a comma separated
list of extra key names which are to be allowed in the config
file. This lets you add more key/value pairs to the config
file intended to be seen in the NSUserDefaults system.<br />
However, you must take care that any key names you choose
do not conflict with variable names used with the GNUstep
Makefiles package or your configuration script may cause
problems when building software.
The <code>.plist</code> files in the GlobalDefaults
subdirectory are merged into the defaults system in an
unpredictable order, but the values from the
GlobalDefaults.plist are merged in <em>after</em> the
other values and will take precedence.<br />
The global defaults files allow packagers and system
administrators to provide defaults settings for all
users of a particular GNUstep installation.<br />
It is recommended that each software package provides its
own defaults in the GlobalDefaults subdirectory, while the
GlobalDefaults.plist file should be reserved for other
system-wide settings.
</p>
<p>
The exact format of the configuration file is expected to
@ -649,10 +653,9 @@ notice and this notice are preserved.
can 'source' in order to define shell variables).<br />
This configuration file uses the escape sequence and
quoting conventions of the standard bourne shell.<br />
The only Keys permitted are those listed above (plus any
specified in the GNUSTEP_EXTRA list), and all consist of
uppercase letters, digits, and underscores, and must
not begin with a digit.<br />
The only Keys permitted are those listed above,
and all consist of uppercase letters, digits, and underscores,
and must not begin with a digit.<br />
A value may be any quoted string (or an unquoted string
containing no white space).<br />
Lines beginning with a hash '#' are deemed comment lines

View file

@ -663,6 +663,81 @@ static void ExtractValuesFromConfig(NSDictionary *config)
ASSIGN_DEFAULT_PATH(gnustepLocalUsersDir, @GNUSTEP_TARGET_LOCAL_USERS_DIR);
}
static void
addDefaults(NSString *defs, NSMutableDictionary *conf)
{
if ([MGR() isReadableFileAtPath: defs] == YES)
{
NSDictionary *d;
NSDictionary *attributes;
attributes = [MGR() fileAttributesAtPath: defs
traverseLink: YES];
if (([attributes filePosixPermissions]
& (0022 & ATTRMASK)) != 0)
{
#if defined(__MINGW__)
fprintf(stderr,
"The file '%S' is writable by someone other than"
" its owner (permissions 0%lo).\nIgnoring it.\n",
[defs fileSystemRepresentation],
(long)[attributes filePosixPermissions]);
#else
fprintf(stderr,
"The file '%s' is writable by someone other than"
" its owner (permissions 0%lo).\nIgnoring it.\n",
[defs fileSystemRepresentation],
(long)[attributes filePosixPermissions]);
#endif
d = nil;
}
else
{
d = [NSDictionary dictionaryWithContentsOfFile: defs];
}
if (d != nil)
{
NSEnumerator *enumerator;
NSString *key;
id extra;
extra = [conf objectForKey: @"GNUSTEP_EXTRA"];
if ([extra isKindOfClass: [NSString class]])
{
extra = [extra componentsSeparatedByString: @","];
}
extra = [extra mutableCopy];
if (extra == nil)
{
extra = [NSMutableArray new];
}
enumerator = [d keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([conf objectForKey: key] == nil)
{
[extra addObject: key];
}
else
{
fprintf(stderr, "Value for key '%s' in '%s' replaces"
" earlier setting.\n", [key UTF8String], [defs UTF8String]);
}
}
[conf addEntriesFromDictionary: d];
if ([extra count] > 0)
{
NSArray *c = [extra copy];
[conf setObject: c forKey: @"GNUSTEP_EXTRA"];
RELEASE(c);
}
RELEASE(extra);
}
}
}
NSMutableDictionary*
GNUstepConfig(NSDictionary *newConfig)
{
@ -763,82 +838,39 @@ GNUstepConfig(NSDictionary *newConfig)
}
else
{
NSEnumerator *e;
NSString *defs;
NSString *path;
gnustepConfigPath
= RETAIN([file stringByDeletingLastPathComponent]);
ParseConfigurationFile(file, conf, nil);
if (nil != [conf objectForKey: @"GNUSTEP_EXTRA"])
{
NSLog(@"Warning: use of GNUSTEP_EXTRA in your GNUstep.conf file is deprecated. Please use a GlobalDefaults.plist instead.\n");
}
/* Merge in any values from property lists in the
* GlobalDefaults directory.
*/
path = [gnustepConfigPath stringByAppendingPathComponent:
@"GlobalDefaults"];
e = [[MGR() directoryContentsAtPath: path] objectEnumerator];
while ((defs = [e nextObject]) != nil)
{
if ([[defs pathExtension] isEqualToString: @"plist"])
{
defs = [path stringByAppendingPathComponent: defs];
addDefaults(defs, conf);
}
}
/* And merge in value from GloablDefaults.plist
*/
defs = [gnustepConfigPath stringByAppendingPathComponent:
@"GlobalDefaults.plist"];
if ([MGR() isReadableFileAtPath: defs] == YES)
{
NSDictionary *d;
NSDictionary *attributes;
attributes = [MGR() fileAttributesAtPath: defs
traverseLink: YES];
if (([attributes filePosixPermissions]
& (0022 & ATTRMASK)) != 0)
{
#if defined(__MINGW__)
fprintf(stderr,
"The file '%S' is writable by someone other than"
" its owner (permissions 0%lo).\nIgnoring it.\n",
[defs fileSystemRepresentation],
(long)[attributes filePosixPermissions]);
#else
fprintf(stderr,
"The file '%s' is writable by someone other than"
" its owner (permissions 0%lo).\nIgnoring it.\n",
[defs fileSystemRepresentation],
(long)[attributes filePosixPermissions]);
#endif
d = nil;
}
else
{
d = [NSDictionary dictionaryWithContentsOfFile: defs];
}
if (d != nil)
{
NSEnumerator *enumerator;
NSString *key;
id extra;
extra = [conf objectForKey: @"GNUSTEP_EXTRA"];
extra = [extra componentsSeparatedByString: @","];
extra = [extra mutableCopy];
if (extra == nil)
{
extra = [NSMutableArray new];
}
enumerator = [d keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([conf objectForKey: key] == nil)
{
[extra addObject: key];
}
else
{
fprintf(stderr, "Key '%s' in '%s' duplicates"
" key in %s\n", [key UTF8String],
[defs UTF8String], [file UTF8String]);
}
}
[conf addEntriesFromDictionary: d];
if ([extra count] > 0)
{
NSArray *c = [extra copy];
[conf setObject: c forKey: @"GNUSTEP_EXTRA"];
RELEASE(c);
}
RELEASE(extra);
}
}
addDefaults(defs, conf);
}
}
else

View file

@ -238,11 +238,10 @@ writeDictionary(NSDictionary *dict, NSString *file)
* or from information compiled in when the base library was
* built.<br />
* In addition to this standard configuration information, this
* domain contains all values from the GlobalDefaults.plist file
* stored in the same directory as the system widw GNUstep.conf
* file. The GlobalDefaults.plist allows packagers and system
* administrators to provide global defaults settings for all
* users of a particular GNUstep installation.
* domain contains all values from property lists store in the
* GlobalDefaults subdirectory or from the GlobalDefaults.plist file
* stored in the same directory as the system wide GNUstep.conf
* file.
* </desc>
* <term><code>NSRegistrationDomain</code> ... volatile</term>
* <desc>