Fixup for problem getting base library resources where multiple versions are installed.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25085 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2007-04-27 11:39:50 +00:00
parent 8f9d8a608f
commit 383cb43c5a
2 changed files with 61 additions and 19 deletions

View file

@ -1,3 +1,9 @@
2007-04-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSBundle.m: Reformat for conding standards. Alter library
resource lookup to find correct version when multiple versions of
the base library are installed and the old unversioned api is used.
2007-04-16 Richard Frith-Macdonald <rfm@gnu.org>
* config/config.forward2.m: Test for forward2 function in runtime.

View file

@ -81,6 +81,9 @@ static NSMapTable *_byIdentifier = NULL;
/* Store the working directory at startup */
static NSString *_launchDirectory = nil;
static NSString *_base_version
= OBJC_STRINGIFY(GNUSTEP_BASE_MAJOR_VERSION.GNUSTEP_BASE_MINOR_VERSION);
/*
* An empty strings file table for use when localization files can't be found.
*/
@ -813,8 +816,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
currentDirectoryPath]);
_gnustep_bundle = RETAIN([self bundleForLibrary: @"gnustep-base"
version: OBJC_STRINGIFY(GNUSTEP_BASE_MAJOR_VERSION.GNUSTEP_BASE_MINOR_VERSION)]);
version: _base_version]);
#if 0
_loadingBundle = [self mainBundle];
handle = objc_open_main_module(stderr);
@ -914,7 +916,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
while (NSNextMapEnumeratorPair(&enumerate, &key, (void **)&bundle))
{
if (bundle->_bundleType == NSBUNDLE_FRAMEWORK
&& [array indexOfObjectIdenticalTo: bundle] == NSNotFound)
&& [array indexOfObjectIdenticalTo: bundle] == NSNotFound)
{
[array addObject: bundle];
}
@ -2233,14 +2235,15 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
}
/*
* We expect to find the library resources into:
* We expect to find the library resources in the GNUSTEP_LIBRARY domain in:
*
* GNUSTEP_LIBRARY/Libraries/<libraryName>/Versions/<interfaceVersion>/Resources/
* Libraries/<libraryName>/Versions/<interfaceVersion>/Resources/
*
* if no <interfaceVersion> is specified, and if can't find any versioned
* resources in those directories, we'll also accept the old unversioned format
* resources in those directories, we'll also accept the old unversioned
* subdirectory:
*
* GNUSTEP_LIBRARY/Libraries/Resources/<libraryName>/
* Libraries/Resources/<libraryName>/
*
*/
paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
@ -2255,6 +2258,28 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
if ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir)
{
/* As a special case, if we have been asked to get the base
* library bundle without a version, we check to see if the
* bundle for the current version is available and use that
* in preference to all others.
* This lets older code (using the non-versioned api) work
* on systems where multiple versions are installed.
*/
if (interfaceVersion == nil
&& [libraryName isEqualToString: @"gnustep-base"])
{
NSString *p;
p = [[[[path stringByAppendingPathComponent: libraryName]
stringByAppendingPathComponent: @"Versions"]
stringByAppendingPathComponent: _base_version]
stringByAppendingPathComponent: @"Resources"];
if ([fm fileExistsAtPath: p isDirectory: &isDir] && isDir)
{
interfaceVersion = _base_version;
}
}
if (interfaceVersion != nil)
{
/* We're looking for a specific version. */
@ -2276,22 +2301,28 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
else
{
/* Any version will do. */
NSString *versionsPath = [[path stringByAppendingPathComponent: libraryName]
stringByAppendingPathComponent: @"Versions"];
NSString *versionsPath;
if ([fm fileExistsAtPath: versionsPath isDirectory: &isDir] && isDir)
versionsPath
= [[path stringByAppendingPathComponent: libraryName]
stringByAppendingPathComponent: @"Versions"];
if ([fm fileExistsAtPath: versionsPath isDirectory: &isDir]
&& isDir)
{
/* TODO: Ignore subdirectories. */
NSEnumerator *fileEnumerator = [fm enumeratorAtPath: versionsPath];
NSEnumerator *fileEnumerator;
NSString *potentialPath;
fileEnumerator = [fm enumeratorAtPath: versionsPath];
while ((potentialPath = [fileEnumerator nextObject]) != nil)
{
potentialPath = [versionsPath
stringByAppendingPathComponent:
[potentialPath
stringByAppendingPathComponent: @"Resources"]];
if ([fm fileExistsAtPath: potentialPath isDirectory: &isDir] && isDir)
potentialPath = [potentialPath
stringByAppendingPathComponent: @"Resources"];
potentialPath = [versionsPath
stringByAppendingPathComponent: potentialPath];
if ([fm fileExistsAtPath: potentialPath
isDirectory: &isDir] && isDir)
{
b = [self bundleWithPath: potentialPath];
@ -2313,9 +2344,14 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
* when we added library resource versioning.
*/
{
NSString *oldResourcesPath = [[path stringByAppendingPathComponent: @"Resources"]
stringByAppendingPathComponent: libraryName];
if ([fm fileExistsAtPath: oldResourcesPath isDirectory: &isDir] && isDir)
NSString *oldResourcesPath;
oldResourcesPath = [path
stringByAppendingPathComponent: @"Resources"];
oldResourcesPath = [oldResourcesPath
stringByAppendingPathComponent: libraryName];
if ([fm fileExistsAtPath: oldResourcesPath
isDirectory: &isDir] && isDir)
{
b = [self bundleWithPath: oldResourcesPath];
if (b != nil && b->_bundleType == NSBUNDLE_BUNDLE)