[ios] Save log.txt file to the root documents directory

Fixes:
1. The log.txt file is saved root documents directory
2. The log.txt is not immediately deleted while creating the zip
3. Zip archive for sharing is created in the tmp directory as before (to be cleaned up automatically)

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn
2025-07-11 12:57:55 +04:00
committed by Konstantin Pastbin
parent cd00dd22a7
commit 8b64225b80

View File

@@ -28,7 +28,8 @@ NSString * const kLoggerSubsystem = [[NSBundle mainBundle] bundleIdentifier];
NSString * const kLoggerCategory = @"OM";
NSString * const kLogFileName = @"log.txt";
NSString * const kZipLogFileExtension = @"zip";
NSString * const kLogFilePath = [[NSFileManager.defaultManager temporaryDirectory] URLByAppendingPathComponent:kLogFileName].path;
NSString * const kLogFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
stringByAppendingPathComponent:kLogFileName];
// TODO: (KK) Review and change this limit after some testing.
NSUInteger const kMaxLogFileSize = 1024 * 1024 * 100; // 100 MB;
@@ -225,13 +226,13 @@ bool AssertMessage(base::SrcPoint const & src, std::string const & message)
}
+ (NSURL *)getZippedLogFile:(NSString *)logFilePath {
NSString * zipFilePath = [[logFilePath stringByDeletingPathExtension] stringByAppendingPathExtension:kZipLogFileExtension];
NSString * zipFileName = [[logFilePath.lastPathComponent stringByDeletingPathExtension] stringByAppendingPathExtension:kZipLogFileExtension];
NSString * zipFilePath = [[NSFileManager.defaultManager temporaryDirectory] URLByAppendingPathComponent:zipFileName].path;
auto const success = CreateZipFromFiles({logFilePath.UTF8String}, zipFilePath.UTF8String);
if (!success) {
LOG(LERROR, ("Failed to zip log file:", kLogFilePath.UTF8String, ". The original file will be returned."));
return [NSURL fileURLWithPath:logFilePath];
}
[self removeFileAtPath:kLogFilePath];
return [NSURL fileURLWithPath:zipFilePath];
}