浏览代码

HTTPConnection: prevent crash when uploading a file exceeding the device's free storage (close #10490)

Felix Paul Kühne 11 年之前
父节点
当前提交
0df2458d1d
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 15 2
      Sources/VLCHTTPConnection.m

+ 15 - 2
Sources/VLCHTTPConnection.m

@@ -166,8 +166,21 @@
 - (void)processContent:(NSData*)data WithHeader:(MultipartMessageHeader*) header
 {
     // here we just write the output from parser to the file.
-    if (_storeFile)
-        [_storeFile writeData:data];
+    if (_storeFile) {
+        @try {
+            [_storeFile writeData:data];
+        }
+        @catch (NSException *exception) {
+            APLog(@"File to write further data because storage is full.");
+        }
+        @finally {
+            [_storeFile closeFile];
+            _storeFile = nil;
+            /* don't block */
+            [self performSelector:@selector(stop) withObject:nil afterDelay:0.1];
+        }
+    }
+
 }
 
 - (void)processEndOfPartWithHeader:(MultipartMessageHeader*)header