Creating path of downloaded file if it doesn't exist #358

Open
wants to merge 1 commit into
from
@@ -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]];