Commit a30a787b authored by Carola Nitz's avatar Carola Nitz

HTTPFileDownloader: don't create files when statuscode was 404

parent 8ddc8c13
......@@ -21,6 +21,7 @@
NSUInteger _receivedDataSize;
NSString *_fileName;
NSURLConnection *_urlConnection;
NSUInteger _statusCode;
}
@end
......@@ -70,22 +71,22 @@
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{
NSUInteger statusCode = [response statusCode];
if (statusCode == 200) {
_statusCode = [response statusCode];
if (_statusCode == 200) {
_expectedDownloadSize = [response expectedContentLength];
[self.delegate downloadStarted];
APLog(@"expected download size: %i", _expectedDownloadSize);
} else {
APLog(@"unhandled status code %i", statusCode);
APLog(@"unhandled status code %i", _statusCode);
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
[self.delegate downloadFailedWithErrorDescription:[NSString stringWithFormat:NSLocalizedString(@"HTTP_DOWNLOAD_FAILED",nil), statusCode]];
[self.delegate downloadFailedWithErrorDescription:[NSString stringWithFormat:NSLocalizedString(@"HTTP_DOWNLOAD_FAILED",nil), _statusCode]];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:_filePath];
if (!fileHandle) {
if (!fileHandle && _statusCode != 404) {
// create file
[[NSFileManager defaultManager] createFileAtPath:_filePath contents:nil attributes:nil];
fileHandle = [NSFileHandle fileHandleForWritingAtPath:_filePath];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment