diff --git a/src/ios/Network/HCPFileDownloader.m b/src/ios/Network/HCPFileDownloader.m index cebe5cf8..2043e9ab 100644 --- a/src/ios/Network/HCPFileDownloader.m +++ b/src/ios/Network/HCPFileDownloader.m @@ -30,6 +30,11 @@ - (void) downloadDataFromUrl:(NSURL*) url requestHeaders:(NSDictionary *)headers - (void) downloadFiles:(NSArray *)filesList fromURL:(NSURL *)contentURL toFolder:(NSURL *)folderURL requestHeaders:(NSDictionary *)headers completionBlock:(HCPFileDownloadCompletionBlock)block { NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; + // Override the default timeout values to cope with large transfers. + // Possible improvement: set the values from config.xml + configuration.timeoutIntervalForResource = 300.0; + configuration.timeoutIntervalForRequest = 300.0; + configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; if (headers) { [configuration setHTTPAdditionalHeaders:headers]; diff --git a/src/ios/Updater/HCPInstallationWorker.m b/src/ios/Updater/HCPInstallationWorker.m index 5a3aa967..361859e3 100644 --- a/src/ios/Updater/HCPInstallationWorker.m +++ b/src/ios/Updater/HCPInstallationWorker.m @@ -172,16 +172,19 @@ - (BOOL)isUpdateValid:(NSError **)error { NSArray *updateFileList = _manifestDiff.updateFileList; for (HCPManifestFile *updatedFile in updateFileList) { - NSURL *fileLocalURL = [_newReleaseFS.downloadFolder URLByAppendingPathComponent:updatedFile.name isDirectory:NO]; - if (![_fileManager fileExistsAtPath:fileLocalURL.path]) { - errorMsg = [NSString stringWithFormat:@"Update validation error! File not found: %@", updatedFile.name]; - break; - } - - NSString *fileMD5 = [[NSData dataWithContentsOfURL:fileLocalURL] md5]; - if (![fileMD5 isEqualToString:updatedFile.md5Hash]) { - errorMsg = [NSString stringWithFormat:@"Update validation error! File's %@ hash %@ doesnt match the hash %@ from manifest file", updatedFile.name, fileMD5, updatedFile.md5Hash]; - break; + // Force the release of the memory allocated to calculate the MD5 hash + @autoreleasepool { + NSURL *fileLocalURL = [_newReleaseFS.downloadFolder URLByAppendingPathComponent:updatedFile.name isDirectory:NO]; + if (![_fileManager fileExistsAtPath:fileLocalURL.path]) { + errorMsg = [NSString stringWithFormat:@"Update validation error! File not found: %@", updatedFile.name]; + break; + } + + NSString *fileMD5 = [[NSData dataWithContentsOfURL:fileLocalURL] md5]; + if (![fileMD5 isEqualToString:updatedFile.md5Hash]) { + errorMsg = [NSString stringWithFormat:@"Update validation error! File's %@ hash %@ doesnt match the hash %@ from manifest file", updatedFile.name, fileMD5, updatedFile.md5Hash]; + break; + } } } @@ -243,32 +246,35 @@ - (BOOL)moveDownloadedFilesToWwwFolder:(NSError **)error { NSArray *updatedFiles = _manifestDiff.updateFileList; NSString *errorMsg = nil; for (HCPManifestFile *manifestFile in updatedFiles) { - // determine paths to the file in installation and www folders - NSURL *pathInInstallationFolder = [_newReleaseFS.downloadFolder URLByAppendingPathComponent:manifestFile.name]; - NSURL *pathInWwwFolder = [_newReleaseFS.wwwFolder URLByAppendingPathComponent:manifestFile.name]; - - // if file already exists in www folder - remove it before copying - if ([fileManager fileExistsAtPath:pathInWwwFolder.path] && ![fileManager removeItemAtURL:pathInWwwFolder error:error]) { - errorMsg = [NSString stringWithFormat:@"Failed to delete old version of the file %@ : %@. Installation failed", - manifestFile.name, [(*error) underlyingErrorLocalizedDesription]]; - break; - } - - // if needed - create subfolders for the new file - NSURL *parentDirectoryPathInWwwFolder = [pathInWwwFolder URLByDeletingLastPathComponent]; - if (![fileManager fileExistsAtPath:parentDirectoryPathInWwwFolder.path]) { - if (![fileManager createDirectoryAtPath:parentDirectoryPathInWwwFolder.path withIntermediateDirectories:YES attributes:nil error:error]) { - errorMsg = [NSString stringWithFormat:@"Failed to create folder structure for file %@ : %@. Installation failed.", + // Force the release of the memory allocated during file copy + @autoreleasepool { + // determine paths to the file in installation and www folders + NSURL *pathInInstallationFolder = [_newReleaseFS.downloadFolder URLByAppendingPathComponent:manifestFile.name]; + NSURL *pathInWwwFolder = [_newReleaseFS.wwwFolder URLByAppendingPathComponent:manifestFile.name]; + + // if file already exists in www folder - remove it before copying + if ([fileManager fileExistsAtPath:pathInWwwFolder.path] && ![fileManager removeItemAtURL:pathInWwwFolder error:error]) { + errorMsg = [NSString stringWithFormat:@"Failed to delete old version of the file %@ : %@. Installation failed", + manifestFile.name, [(*error) underlyingErrorLocalizedDesription]]; + break; + } + + // if needed - create subfolders for the new file + NSURL *parentDirectoryPathInWwwFolder = [pathInWwwFolder URLByDeletingLastPathComponent]; + if (![fileManager fileExistsAtPath:parentDirectoryPathInWwwFolder.path]) { + if (![fileManager createDirectoryAtPath:parentDirectoryPathInWwwFolder.path withIntermediateDirectories:YES attributes:nil error:error]) { + errorMsg = [NSString stringWithFormat:@"Failed to create folder structure for file %@ : %@. Installation failed.", + manifestFile.name, [(*error) underlyingErrorLocalizedDesription]]; + break; + } + } + + // copy new file into www folder + if (![fileManager moveItemAtURL:pathInInstallationFolder toURL:pathInWwwFolder error:error]) { + errorMsg = [NSString stringWithFormat:@"Failed to copy file %@ into www folder: %@. Installation failed.", manifestFile.name, [(*error) underlyingErrorLocalizedDesription]]; break; } - } - - // copy new file into www folder - if (![fileManager moveItemAtURL:pathInInstallationFolder toURL:pathInWwwFolder error:error]) { - errorMsg = [NSString stringWithFormat:@"Failed to copy file %@ into www folder: %@. Installation failed.", - manifestFile.name, [(*error) underlyingErrorLocalizedDesription]]; - break; } }