Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions Classes/ASIHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]];
Expand Down