fix migration of important files

This commit is contained in:
Danmei Chen 2019-01-09 14:35:24 +01:00
parent ebe3c0133b
commit e4e0c5aac8
4 changed files with 49 additions and 30 deletions

View file

@ -321,9 +321,9 @@ static UICompositeViewDescription *compositeDescription = nil;
LOGW(@"Exception while destroying linphone core: %@", e);
} @finally {
if ([NSFileManager.defaultManager
isDeletableFileAtPath:[LinphoneManager dataFile:@"linphonerc"]] == YES) {
isDeletableFileAtPath:[LinphoneManager preferenceFile:@"linphonerc"]] == YES) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager dataFile:@"linphonerc"]
removeItemAtPath:[LinphoneManager preferenceFile:@"linphonerc"]
error:nil];
}
#ifdef DEBUG

View file

@ -160,6 +160,7 @@ typedef struct _LinphoneManagerSounds {
+ (BOOL)copyFile:(NSString*)src destination:(NSString*)dst override:(BOOL)override;
+ (PHFetchResult *)getPHAssets:(NSString *)key;
+ (NSString*)bundleFile:(NSString*)file;
+ (NSString *)preferenceFile:(NSString *)file;
+ (NSString *)documentFile:(NSString *)file;
+ (NSString*)dataFile:(NSString*)file;
+ (NSString*)cacheDirectory;

View file

@ -266,6 +266,7 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre
_linphoneManagerAddressBookMap = [[OrderedDictionary alloc] init];
pushCallIDs = [[NSMutableArray alloc] init];
_isTesting = [LinphoneManager isRunningTests];
[self migrateImportantFiles];
[self renameDefaultSettings];
[self copyDefaultSettings];
[self overrideDefaultSettings];
@ -343,28 +344,6 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre
}
[self lpConfigSetBool:NO forKey:@"store_friends" inSection:@"misc"]; //so far, storing friends in files is not needed. may change in the future.
// migration of important file, move these files to app library.
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"linphonerc"] destination:[LinphoneManager dataFile:@"linphonerc"] override:TRUE]) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"linphonerc"]
error:nil];
}
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"linphone_chats.db"] destination:[LinphoneManager dataFile:@"linphone_chats.db"] override:TRUE]) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"linphone_chats.db"]
error:nil];
}
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"zrtp_secrets"] destination:[LinphoneManager dataFile:@"zrtp_secrets"] override:TRUE]) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"zrtp_secrets"]
error:nil];
}
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"zrtp_secrets.bkp"] destination:[LinphoneManager dataFile:@"zrtp_secrets.bkp"] override:TRUE]) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"zrtp_secrets.bkp"]
error:nil];
}
}
static int check_should_migrate_images(void *data, int argc, char **argv, char **cnames) {
@ -2502,12 +2481,34 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
linphone_core_refresh_registers(theLinphoneCore); // just to make sure REGISTRATION is up to date
}
- (void)migrateImportantFiles {
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"linphonerc"] destination:[LinphoneManager preferenceFile:@"linphonerc"] override:TRUE])
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"linphonerc"]
error:nil];
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"linphone_chats.db"] destination:[LinphoneManager dataFile:@"linphone_chats.db"] override:TRUE])
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"linphone_chats.db"]
error:nil];
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"zrtp_secrets"] destination:[LinphoneManager dataFile:@"zrtp_secrets"] override:TRUE])
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"zrtp_secrets"]
error:nil];
if ([LinphoneManager copyFile:[LinphoneManager documentFile:@"zrtp_secrets.bkp"] destination:[LinphoneManager dataFile:@"zrtp_secrets.bkp"] override:TRUE])
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager documentFile:@"zrtp_secrets.bkp"]
error:nil];
}
- (void)renameDefaultSettings {
// rename .linphonerc to linphonerc to ease debugging: when downloading
// containers from MacOSX, Finder do not display hidden files leading
// to useless painful operations to display the .linphonerc file
NSString *src = [LinphoneManager dataFile:@".linphonerc"];
NSString *dst = [LinphoneManager dataFile:@"linphonerc"];
NSString *src = [LinphoneManager documentFile:@".linphonerc"];
NSString *dst = [LinphoneManager preferenceFile:@"linphonerc"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *fileError = nil;
if ([fileManager fileExistsAtPath:src]) {
@ -2528,7 +2529,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
if (IPAD && [[NSFileManager defaultManager] fileExistsAtPath:srcIpad]) {
src = srcIpad;
}
NSString *dst = [LinphoneManager dataFile:@"linphonerc"];
NSString *dst = [LinphoneManager preferenceFile:@"linphonerc"];
[LinphoneManager copyFile:src destination:dst override:FALSE];
}
@ -2538,7 +2539,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
if (IPAD && [[NSFileManager defaultManager] fileExistsAtPath:factoryIpad]) {
factory = factoryIpad;
}
NSString *confiFileName = [LinphoneManager dataFile:@"linphonerc"];
NSString *confiFileName = [LinphoneManager preferenceFile:@"linphonerc"];
_configDb = lp_config_new_with_factory([confiFileName UTF8String], [factory UTF8String]);
}
#pragma mark - Audio route Functions
@ -2889,8 +2890,25 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
return [documentsPath stringByAppendingPathComponent:file];
}
+ (NSString *)preferenceFile:(NSString *)file {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *writablePath = [paths objectAtIndex:0];
NSString *fullPath = [writablePath stringByAppendingString:@"/Preferences/linphone/"];
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
NSError *error;
LOGI(@"Preference path %@ does not exist, creating it.",fullPath);
if (![[NSFileManager defaultManager] createDirectoryAtPath:fullPath
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
LOGE(@"Create preference path directory error: %@",error.description);
}
}
return [fullPath stringByAppendingPathComponent:file];
}
+ (NSString *)dataFile:(NSString *)file {
// TODO : migrate with function dataFile of submodule
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *writablePath = [paths objectAtIndex:0];
NSString *fullPath = [writablePath stringByAppendingString:@"/linphone/"];

View file

@ -997,7 +997,7 @@ void update_hash_cbs(LinphoneAccountCreator *creator, LinphoneAccountCreatorStat
if ([LinphoneManager.instance lpConfigBoolForKey:@"send_logs_include_linphonerc_and_chathistory"]) {
// retrieve linphone rc
[attachments
addObject:@[ [LinphoneManager dataFile:@"linphonerc"], @"text/plain", @"linphone-configuration.rc" ]];
addObject:@[ [LinphoneManager preferenceFile:@"linphonerc"], @"text/plain", @"linphone-configuration.rc" ]];
// retrieve historydb
[attachments addObject:@[