IOSAD-202 fixes: wrong PER_USER_DIRECTORY on macOS

IOS-2736
Andreas Buff 2 years ago
parent 4649bc2a13
commit 91ab1a4f32

@ -9,7 +9,7 @@
@import Foundation;
#ifdef IS_IOS_BUILD
#import <pEp4iosIntern/pEp4iosIntern.h> //DIRK: //BUFF: !!!
#import <pEp4iosIntern/pEp4iosIntern.h>
#endif
#import "PEPObjCAdapter.h"
@ -114,13 +114,8 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
+ (void)initialize
{
s_homeURL = [self createApplicationDirectory];
// The engine will put its per_user_directory under this directory.
setenv("HOME", [[s_homeURL path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
// This sets the engine's per_machine_directory under iOS.
[self setPerMachineDirectory:s_homeURL];
[self setupPerUserDirectory];
[self setupPerMachineDirectory];
}
+ (NSURL *)homeURL
@ -128,38 +123,24 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
return s_homeURL;
}
/**
Looks up (and creates if necessary) a pEp directory under "Application Support".
@return A URL pointing a pEp directory under "Application Support".
*/
+ (NSURL *)createApplicationDirectoryOSX
{
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *dirPath = nil;
// Find the application support directory in the home directory.
NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
if ([appSupportDir count] > 0)
{
// Append the bundle ID to the URL for the
// Application Support directory.
// Mainly needed for OS X, but doesn't do any harm on iOS
dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:s_pEpHomeComponent];
// If the directory does not exist, this method creates it.
// This method is only available in OS X v10.7 and iOS 5.0 or later.
NSError *theError = nil;
if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
attributes:nil error:&theError])
{
// Handle the error.
return nil;
}
}
+ (void)setupPerUserDirectory {
// The Engine uses the home env as per-user-directory. We hijack that on iOS.
#if TARGET_OS_IPHONE
s_homeURL = [self createApplicationDirectory];
// The engine will put its per_user_directory under this directory.
setenv("HOME", [[s_homeURL path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
#else
// For macOS there is nothing toDo.
#endif
}
return dirPath;
+ (void)setupPerMachineDirectory {
#if TARGET_OS_IPHONE
[self setPerMachineDirectory:[self homeURL]];
#else
NSURL *perMachineDirMac = [[NSURL alloc] initWithString:"/Library/Application Support/pEp"]
[self setPerMachineDirectory:];
#endif
}
/**
@ -169,7 +150,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
*/
+ (NSURL *)createApplicationDirectoryiOS
{
#ifdef IS_IOS_BUILD //BUFF: DIRK: //!!!:
#ifdef IS_IOS_BUILD
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *containerUrl = [fm containerURLForSecurityApplicationGroupIdentifier:appGroupIdentifier];
NSLog(@"containerUrl '%@'", containerUrl);
@ -195,8 +176,6 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
}
return dirPath;
#else
return [NSURL URLWithString:@"//BUFF:!!!!"];
#endif
}
@ -214,11 +193,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
*/
+ (NSURL *)createApplicationDirectory
{
#if TARGET_OS_IPHONE
return [self createApplicationDirectoryiOS];
#else
return [self createApplicationDirectoryOSX];
#endif
}
/**
@ -246,7 +221,7 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
+ (void)copyAssetsIntoDocumentsDirectory:(NSBundle *)srcBundle
fileName:(NSString *)fileName {
#ifdef IS_IOS_BUILD //BUFF: DIRK: //!!!:
#ifdef IS_IOS_BUILD
NSString *systemDir = [NSString stringWithUTF8String:perMachineDirectory];
if(!(srcBundle && systemDir && fileName)) {
@ -277,7 +252,8 @@ static id<PEPPassphraseProviderProtocol> s_passphraseProvider = nil;
#if TARGET_OS_IPHONE
[PEPObjCAdapter copyAssetsIntoDocumentsDirectory:rootBundle
fileName:@"system.db"];
#else
// On macOS the installer must put that in place.
#endif
}

Loading…
Cancel
Save