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]];