Browse files

Update ASIHTTPRequest.m

Creating path of downloaded file if it doesn't exist
  • Loading branch information...
1 parent 3ed0b3c commit 3eb10882639e1adb5d262eed7287e229ea474a45 @refaelos committed Mar 3, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 Classes/ASIHTTPRequest.m
View
20 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]];

0 comments on commit 3eb1088

Please sign in to comment.