From 3eb10882639e1adb5d262eed7287e229ea474a45 Mon Sep 17 00:00:00 2001 From: Refael Dakar Date: Sun, 3 Mar 2013 16:36:45 +0200 Subject: [PATCH] Update ASIHTTPRequest.m Creating path of downloaded file if it doesn't exist --- Classes/ASIHTTPRequest.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Classes/ASIHTTPRequest.m b/Classes/ASIHTTPRequest.m index 8dd162c3..7bede249 100644 --- a/Classes/ASIHTTPRequest.m +++ b/Classes/ASIHTTPRequest.m @@ -3446,6 +3446,16 @@ - (void)handleStreamComplete // Response should already have been inflated, move the temporary file to the destination path } else { + NSError *tmperror; + + if (![[NSFileManager defaultManager] fileExistsAtPath:[self downloadDestinationPath]]) { + [[NSFileManager defaultManager] createDirectoryAtPath:[self downloadDestinationPath] + withIntermediateDirectories:YES + attributes:nil + error:&tmperror]; + } + [[NSFileManager defaultManager] removeItemAtPath:[self downloadDestinationPath] error:nil]; + NSError *moveError = nil; [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryUncompressedDataDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; if (moveError) { @@ -3467,6 +3477,16 @@ - (void)handleStreamComplete //Move the temporary file to the destination path if (!fileError) { + NSError *tmperror; + + if (![[NSFileManager defaultManager] fileExistsAtPath:[self downloadDestinationPath]]) { + [[NSFileManager defaultManager] createDirectoryAtPath:[self downloadDestinationPath] + withIntermediateDirectories:YES + attributes:nil + error:&tmperror]; + } + [[NSFileManager defaultManager] removeItemAtPath:[self downloadDestinationPath] error:nil]; + [[[[NSFileManager alloc] init] autorelease] moveItemAtPath:[self temporaryFileDownloadPath] toPath:[self downloadDestinationPath] error:&moveError]; if (moveError) { fileError = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASIFileManagementError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to move file from '%@' to '%@'",[self temporaryFileDownloadPath],[self downloadDestinationPath]],NSLocalizedDescriptionKey,moveError,NSUnderlyingErrorKey,nil]];