From 68860ba25f5a52b9cfc2ccfb2b2977615b081e29 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 6 Jul 2021 17:41:09 +0200 Subject: [PATCH] add logs for remove item and move log file to dataPath --- Classes/ChatConversationView.m | 17 ++++++----------- Classes/LinphoneManager.m | 21 ++++++++++++++++++--- Classes/LinphoneUI/UIChatBubbleTextCell.m | 18 +++++++++++++++--- Classes/Utils/Log.m | 3 ++- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 428ee958b..a365d68e6 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -373,17 +373,6 @@ static UICompositeViewDescription *compositeDescription = nil; } } --(void) nsDataWrite:(NSData *)data { - NSString* groupName = [NSString stringWithFormat:@"group.%@.linphoneExtension",[[NSBundle mainBundle] bundleIdentifier]]; - NSError *error = nil; - NSString *path =[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupName] path]; - NSString *fullCacheFilePathPath = [NSString stringWithFormat:@"%@/%@",path,@"nsData"]; - [[NSFileManager defaultManager] removeItemAtURL:[NSURL fileURLWithPath:fullCacheFilePathPath] error:&error]; - if (![data writeToFile:fullCacheFilePathPath atomically:YES]) { - NSLog(@"nsDataWrite error %@",error); - } -} - -(NSData *) nsDataRead { NSString* groupName = [NSString stringWithFormat:@"group.%@.linphoneExtension",[[NSBundle mainBundle] bundleIdentifier]]; NSString *path =[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupName] path]; @@ -1347,6 +1336,9 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog + (void)writeFileInCache:(NSData *)data name:(NSString *)name { NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name]; + if (name || [name isEqualToString:@""]) { + LOGW(@"try to write file in %@", filePath); + } [[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil]; @@ -1393,6 +1385,9 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog // get the url of localfile NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName]; NSURL *localURL = nil; + if (fileName || [fileName isEqualToString:@""]) { + LOGW(@"[writeFileInICloud] try to write file in %@", filePath); + } if ([fileManager createFileAtPath:filePath contents:data attributes:nil]) { localURL = [NSURL fileURLWithPath:filePath]; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index d54fecaa4..8628e2072 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1720,7 +1720,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { fileError ? fileError.localizedDescription : @"successfully"); } else { [fileManager moveItemAtPath:src toPath:dst error:&fileError]; - LOGI(@"%@ moving to %@ %@", dst, src, fileError ? fileError.localizedDescription : @"successfully"); + LOGW(@"%@ moving to %@ %@", dst, src, fileError ? fileError.localizedDescription : @"successfully"); } } } @@ -1846,7 +1846,21 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } + (NSString *)cacheDirectory { - LinphoneFactory *factory = linphone_factory_get(); + NSURL *basePath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:kLinphoneMsgNotificationAppGroupId]; + NSString *fullPath = [[basePath path] stringByAppendingString:@"/Library/Caches/"]; + if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) { + NSError *error; + LOGW(@"Download path %@ does not exist, creating it.", fullPath); + if (![[NSFileManager defaultManager] createDirectoryAtPath:fullPath + withIntermediateDirectories:YES + attributes:nil + error:&error]) { + LOGE(@"Create download path directory error: %@", error.description); + } + } + return fullPath; + + /*LinphoneFactory *factory = linphone_factory_get(); NSString *cachePath = [NSString stringWithUTF8String:linphone_factory_get_download_dir(factory, kLinphoneMsgNotificationAppGroupId.UTF8String)]; BOOL isDir = NO; NSError *error; @@ -1856,8 +1870,9 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { withIntermediateDirectories:NO attributes:nil error:&error]; + LOGW(@"create new cache directory"); } - return cachePath; + return cachePath;*/ } + (NSString *)oldPreferenceFile:(NSString *)file { diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 7dd82eaff..704ca72be 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -74,7 +74,13 @@ if ([encrptedFilePaths count] > 0) { for(NSString *path in [encrptedFilePaths allValues]) { if (![path isEqualToString:@""]) { + LOGW(@"[vfs]s remove item at %@",path); + if ([path isEqualToString:[LinphoneManager cacheDirectory]]) { + LOGE(@"[vfs] something is wrong, can not delete the cache directory"); + break; + } [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; + } } [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfiles" inMessage:_message]; @@ -85,9 +91,15 @@ if (filePath) { if (![filePath isEqualToString:@""]) { NSError *error = nil; - [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; - if (error) { - LOGI(@"clean failed %@", error.description); + LOGW(@"[vfs] remove item at %@",filePath); + if ([filePath isEqualToString:[LinphoneManager cacheDirectory]]) { + LOGE(@"[vfs] something is wrong, can not delete the cache directory"); + } else { + [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; + + if (error) { + LOGI(@"clean failed %@", error.description); + } } } [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfile" inMessage:_message]; diff --git a/Classes/Utils/Log.m b/Classes/Utils/Log.m index b3cfba62f..c7fe474c8 100644 --- a/Classes/Utils/Log.m +++ b/Classes/Utils/Log.m @@ -48,7 +48,8 @@ asl_add_log_file(NULL, STDERR_FILENO); stderrInUse = YES; } - linphone_core_set_log_collection_path([LinphoneManager cacheDirectory].UTF8String); + LinphoneFactory *factory = linphone_factory_get(); + linphone_core_set_log_collection_path(linphone_factory_get_data_dir(factory, kLinphoneMsgNotificationAppGroupId.UTF8String)); linphone_core_set_log_handler(linphone_iphone_log_handler); linphone_core_enable_log_collection(enabled); if (level == 0) {