Use empty string as filename for avoiding reading file.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22151 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-12-05 14:43:46 +00:00
parent 0e83f2a624
commit 5e7bc564c8
2 changed files with 35 additions and 22 deletions

View file

@ -468,10 +468,9 @@ notice and this notice are preserved.
option of the <code>configure</code> script.<br />
If you want to <em>force</em> the internal defaults to be used,
you can use <code>--with-config-file=</code> to specify a path
whose last component is the filename
<code>.GNUstep.conf-ignore</code> as the base library
with a trailing '/' (ie with no filename) as the base library
will refrain from trying to load configuration from a file
of that name.<br />
of no name.<br />
System paths are defined by the following:
</p>
<deflist>
@ -508,7 +507,7 @@ notice and this notice are preserved.
<term>GNUSTEP_USER_CONFIG_FILE</term>
<desc>Name of user configuration file (eg. '.GNUstep.conf')
relative to the user's home directory.<br />
Can be specified as <code>.GNUstep.conf-ignore</code> to ensure
Can be specified as an empty string to ensure
that no user specific config file is loaded.
</desc>
<term>GNUSTEP_USER_DEFAULTS_DIR</term>
@ -626,10 +625,10 @@ notice and this notice are preserved.
distribution as a relocatable package, so it can be installed
anywhere, but users can't accidentally change the config file
and mess up paths, you can specify the config file name as
<code>.GNUstep.conf-ignore</code> so that the base library will
a path with a trailing slash so that the base library will
<em>not</em> read it, and will use the builtin default values.<br />
To do this, you would configure using the options
<code>--with-config-file=./.GNUstep.conf-ignore</code> and
<code>--with-config-file=./</code> and
<code>--with-default-file=myConfig</code> where <em>myConfig</em>
is a file containing the paths you want to use relative to the
location the base library gets installed in.<br />
@ -645,8 +644,7 @@ notice and this notice are preserved.
configuration file and may generally override values from the
main file. To prevent the use specific file from being read,
the system manager may define GNUSTEP_USER_CONFIG_FILE in the
main file to be <code>.GNUstep.conf-ignore</code> or to be
an empty string.<br />
main file to be an empty string.<br />
In any case, the user specific file is <em>not</em> read if a
program is running setuid.
</p>

View file

@ -394,6 +394,7 @@ GNUstepConfig(NSDictionary *newConfig)
{
NSString *file = nil;
BOOL fromEnvironment = YES;
BOOL bareDirectory = NO;
conf = [[NSMutableDictionary alloc] initWithCapacity: 32];
@ -408,6 +409,16 @@ GNUstepConfig(NSDictionary *newConfig)
file = [NSString stringWithCString:
STRINGIFY(GNUSTEP_CONFIG_FILE)];
}
/*
* Is the file missing from the path ... if so we won't
* be reading it.
*/
if ([file hasSuffix: @"/"] || [file hasSuffix: @"\\"])
{
bareDirectory = YES;
}
/*
* Special case ... if the config file location begins './'
* then we determine it's actual path by working relative
@ -459,9 +470,16 @@ GNUstepConfig(NSDictionary *newConfig)
}
#endif
}
gnustepConfigPath
= RETAIN([file stringByDeletingLastPathComponent]);
ParseConfigurationFile(file, conf);
if (bareDirectory == YES)
{
gnustepConfigPath = RETAIN(file);
}
else
{
gnustepConfigPath
= RETAIN([file stringByDeletingLastPathComponent]);
ParseConfigurationFile(file, conf);
}
}
else
{
@ -537,9 +555,12 @@ UserConfig(NSMutableDictionary *config, NSString *userName)
NSString *path;
file = RETAIN([config objectForKey: @"GNUSTEP_USER_CONFIG_FILE"]);
home = NSHomeDirectoryForUser(userName);
path = [home stringByAppendingPathComponent: file];
ParseConfigurationFile(path, config);
if ([file length] > 0)
{
home = NSHomeDirectoryForUser(userName);
path = [home stringByAppendingPathComponent: file];
ParseConfigurationFile(path, config);
}
/*
* We don't let the user config file override the GNUSTEP_USER_CONFIG_FILE
* variable ... that would be silly/pointless.
@ -635,9 +656,8 @@ static void ShutdownPathUtilities(void)
* idea to specify path values in the config file as singly quoted
* strings to avoid having to double all occurrences of the backslash.<br />
* Returns a dictionary of the (key,value) pairs.<br/ >
* If the file does not exist, or its name is
* <code>.GNUstep.conf-ignore</code> then nothing is read and the
* function makes no changes to dict and returns NO.
* If the file does not exist,
* the function makes no changes to dict and returns NO.
*/
static BOOL
ParseConfigurationFile(NSString *fileName, NSMutableDictionary *dict)
@ -655,11 +675,6 @@ ParseConfigurationFile(NSString *fileName, NSMutableDictionary *dict)
BOOL wantVal = NO;
NSString *key = nil;
if ([[fileName lastPathComponent] isEqual: @".GNUstep.conf-ignore"] == YES)
{
return NO; // Special case filename ... must ignore this.
}
if ([MGR() isReadableFileAtPath: fileName] == NO)
{
return NO;