Repository: cordova-plugin-file-transfer Updated Branches: refs/heads/master b7c500e1e -> c97f544ef
CB-9969 Filetransfer upload error deletes original file Adds corresponding test and fixes for iOS and Windows Also fixes filetransfer.spec.9, which used an incorrect path in the root.getFile call. 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/c97f544e Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/c97f544e Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/c97f544e Branch: refs/heads/master Commit: c97f544ef8511605b5fd74321cdf548d380b5601 Parents: b7c500e Author: daserge <[email protected]> Authored: Thu Nov 26 22:52:54 2015 +0300 Committer: daserge <[email protected]> Committed: Thu Nov 26 23:07:04 2015 +0300 ---------------------------------------------------------------------- src/ios/CDVFileTransfer.m | 4 +++- src/windows/FileTransferProxy.js | 6 ++--- tests/tests.js | 42 ++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/c97f544e/src/ios/CDVFileTransfer.m ---------------------------------------------------------------------- diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index ee32b92..aa60c52 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -631,7 +631,9 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) delegate.backgroundTaskID = UIBackgroundTaskInvalid; } - [self removeTargetFile]; + if (self.direction == CDV_TRANSFER_DOWNLOAD) { + [self removeTargetFile]; + } } - (void)cancelTransferWithError:(NSURLConnection*)connection errorMessage:(NSString*)errorMessage http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/c97f544e/src/windows/FileTransferProxy.js ---------------------------------------------------------------------- diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js index 635f3d6..973734a 100644 --- a/src/windows/FileTransferProxy.js +++ b/src/windows/FileTransferProxy.js @@ -230,11 +230,9 @@ exec(win, fail, 'FileTransfer', 'upload', currentUploadOp.promise = null; } - // Cleanup, remove incompleted file + // Report the upload error back getTransferError.then(function(transferError) { - storageFile.deleteAsync().then(function() { - errorCallback(transferError); - }); + errorCallback(transferError); }); }, function (evt) { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/c97f544e/tests/tests.js ---------------------------------------------------------------------- diff --git a/tests/tests.js b/tests/tests.js index c6d7a70..5c5df8a 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -450,7 +450,7 @@ exports.defineAutoTests = function () { expect(transfer.onprogress).toHaveBeenCalled(); // check that there is no file - root.getFile(localFilePath, null, unexpectedCallbacks.fileSystemWin, done); + root.getFile(fileName, null, unexpectedCallbacks.fileSystemWin, done); }; // abort at the first onprogress event @@ -972,6 +972,46 @@ exports.defineAutoTests = function () { // NOTE: removing uploadOptions cause Android to timeout transfer.upload(localFilePath, fileURL, uploadWin, unexpectedCallbacks.httpFail, uploadOptions); }, UPLOAD_TIMEOUT); + + it("filetransfer.spec.34 should not delete a file on upload error", function (done) { + + var fileURL = SERVER + '/upload'; + + var uploadFail = function (e) { + expect(e.code).toBe(FileTransferError.ABORT_ERR); + expect(transfer.onprogress).toHaveBeenCalled(); + + // check that the file is there + root.getFile(fileName, null, function(entry) { + expect(entry).toBeDefined(); + + // delay calling done() to wait for the bogus abort() + setTimeout(done, GRACE_TIME_DELTA * 2); + }, function(err) { + expect(err).not.toBeDefined(err && err.code); + done(); + }); + }; + + var fileWin = function () { + + expect(transfer.abort).not.toThrow(); + + // NOTE: removing uploadOptions cause Android to timeout + transfer.upload(localFilePath, fileURL, unexpectedCallbacks.httpWin, uploadFail, uploadOptions); + + // abort at the first onprogress event + transfer.onprogress = function (event) { + if (event.loaded > 0) { + transfer.abort(); + } + }; + + spyOn(transfer, 'onprogress').and.callThrough(); + }; + + writeFile(root, fileName, new Array(100000).join('aborttest!'), fileWin); + }, UPLOAD_TIMEOUT); }); }); }); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
