cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject git commit: iOS: Fix error where files were not removed on abort
Date Fri, 28 Mar 2014 14:36:30 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/dev 223d08626 -> 2309e0e76


iOS: Fix error where files were not removed on abort


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/2309e0e7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/2309e0e7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/2309e0e7

Branch: refs/heads/dev
Commit: 2309e0e76ca7f4db63e273be75dfd7332b6eb824
Parents: 223d086
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Mar 28 10:36:01 2014 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Mar 28 10:36:01 2014 -0400

----------------------------------------------------------------------
 src/ios/CDVFileTransfer.m | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/2309e0e7/src/ios/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index d87bb94..a1eeef2 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -587,7 +587,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
 {
     NSFileManager* fileMgr = [NSFileManager defaultManager];
 
-    [fileMgr removeItemAtPath:self.target error:nil];
+    [fileMgr removeItemAtPath:[self targetFilePath] error:nil];
 }
 
 - (void)cancelTransfer:(NSURLConnection*)connection
@@ -612,6 +612,21 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     [self.command.commandDelegate sendPluginResult:result callbackId:callbackId];
 }
 
+- (NSString *)targetFilePath
+{
+    NSString *path = nil;
+    CDVFilesystemURL *sourceURL = [CDVFilesystemURL fileSystemURLWithString:self.target];
+    if (sourceURL && sourceURL.fileSystemName != nil) {
+        // This requires talking to the current CDVFile plugin
+        NSObject<CDVFileSystem> *fs = [self.filePlugin filesystemForURL:sourceURL];
+        path = [fs filesystemPathForURL:sourceURL];
+    } else {
+        // Extract the path part out of a file: URL.
+        path = [self.target hasPrefix:@"/"] ? [self.target copy] : [(NSURL *)[NSURL URLWithString:self.target]
path];
+    }
+    return path;
+}
+
 - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
 {
     NSError* __autoreleasing error = nil;
@@ -642,20 +657,11 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     }
     if ((self.direction == CDV_TRANSFER_DOWNLOAD) && (self.responseCode >= 200)
&& (self.responseCode < 300)) {
         // Download response is okay; begin streaming output to file
-        NSString *filePath = nil;
-        CDVFilesystemURL *sourceURL = [CDVFilesystemURL fileSystemURLWithString:self.target];
-        if (sourceURL && sourceURL.fileSystemName != nil) {
-            // This requires talking to the current CDVFile plugin
-            NSObject<CDVFileSystem> *fs = [self.filePlugin filesystemForURL:sourceURL];
-            filePath = [fs filesystemPathForURL:sourceURL];
-        } else {
-            // Extract the path part out of a file: URL.
-            NSString* filePath = [self.target hasPrefix:@"/"] ? [self.target copy] : [(NSURL
*)[NSURL URLWithString:self.target] path];
-            if (filePath == nil) {
-                // We couldn't find the asset.  Send the appropriate error.
-                [self cancelTransferWithError:connection errorMessage:[NSString stringWithFormat:@"Could
not create target file"]];
-                return;
-            }
+        NSString *filePath = [self targetFilePath];
+        if (filePath == nil) {
+            // We couldn't find the asset.  Send the appropriate error.
+            [self cancelTransferWithError:connection errorMessage:[NSString stringWithFormat:@"Could
not create target file"]];
+            return;
         }
 
         NSString* parentPath = [filePath stringByDeletingLastPathComponent];


Mime
View raw message