Explorar el Código

HTTPFileDownloader: don't create files when statuscode was 404

Carola Nitz hace 11 años
padre
commit
a30a787ba9
Se han modificado 1 ficheros con 6 adiciones y 5 borrados
  1. 6 5
      Sources/VLCHTTPFileDownloader.m

+ 6 - 5
Sources/VLCHTTPFileDownloader.m

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