Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

213 i os large transfer timeout #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ios/Network/HCPFileDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
72 changes: 39 additions & 33 deletions src/ios/Updater/HCPInstallationWorker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down