You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/05/25 06:50:52 UTC
ios commit: [CB-3514] Remove partially-downloaded files when
FileTransfer fails
Updated Branches:
refs/heads/master bd9953703 -> 7bc06d59f
[CB-3514] Remove partially-downloaded files when FileTransfer fails
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/7bc06d59
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/7bc06d59
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/7bc06d59
Branch: refs/heads/master
Commit: 7bc06d59fb30bc56b6b824c7374d2e5b7f62dda7
Parents: bd99537
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri May 24 23:34:26 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri May 24 23:41:48 2013 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVFileTransfer.h | 1 +
CordovaLib/Classes/CDVFileTransfer.m | 28 +++++++++++++++++-----------
2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7bc06d59/CordovaLib/Classes/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.h b/CordovaLib/Classes/CDVFileTransfer.h
index 233a114..35e3fdd 100644
--- a/CordovaLib/Classes/CDVFileTransfer.h
+++ b/CordovaLib/Classes/CDVFileTransfer.h
@@ -61,6 +61,7 @@ extern NSString* const kOptionsKeyCookie;
@interface CDVFileTransferDelegate : NSObject {}
- (void)updateBytesExpected:(NSInteger)newBytesExpected;
+- (void)cancelTransfer:(NSURLConnection*)connection;
@property (strong) NSMutableData* responseData; // atomic
@property (nonatomic, strong) CDVFileTransfer* command;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7bc06d59/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 8391b3b..0f6b174 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -348,13 +348,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
CDVFileTransferDelegate* delegate = [activeTransfers objectForKey:objectId];
if (delegate != nil) {
- [delegate.connection cancel];
- [activeTransfers removeObjectForKey:objectId];
-
- // delete uncomplete file
- NSFileManager* fileMgr = [NSFileManager defaultManager];
- [fileMgr removeItemAtPath:delegate.target error:nil];
-
+ [delegate cancelTransfer:delegate.connection];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[self createFileTransferError:CONNECTION_ABORTED AndSource:delegate.source AndTarget:delegate.target]];
[self.commandDelegate sendPluginResult:result callbackId:delegate.callbackId];
}
@@ -570,13 +564,26 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
self.command.backgroundTaskID = UIBackgroundTaskInvalid;
}
+- (void)removeTargetFile
+{
+ NSFileManager* fileMgr = [NSFileManager defaultManager];
+
+ [fileMgr removeItemAtPath:self.target error:nil];
+}
+
+- (void)cancelTransfer:(NSURLConnection*)connection
+{
+ [connection cancel];
+ [self.command.activeTransfers removeObjectForKey:self.objectId];
+ [self removeTargetFile];
+}
+
- (void)cancelTransferWithError:(NSURLConnection*)connection errorMessage:(NSString*)errorMessage
{
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsDictionary:[self.command createFileTransferError:FILE_NOT_FOUND_ERR AndSource:self.source AndTarget:self.target AndHttpStatus:self.responseCode AndBody:errorMessage]];
NSLog(@"File Transfer Error: %@", errorMessage);
- [connection cancel];
- [self.command.activeTransfers removeObjectForKey:self.objectId];
+ [self cancelTransfer:connection];
[self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
}
@@ -641,8 +648,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
NSLog(@"File Transfer Error: %@", [error localizedDescription]);
- // remove connection for activeTransfers
- [command.activeTransfers removeObjectForKey:objectId];
+ [self cancelTransfer:connection];
[self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
}