Merge pull request #9454 from nextcloud/stable13-9245-fix-race-condition-when-preparing-upload-folder

[stable13] Fix race condition when preparing upload folder
This commit is contained in:
Morris Jobke 2018-05-14 13:41:47 +02:00 committed by GitHub
commit edd5712c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -576,7 +576,6 @@ OC.Uploader.prototype = _.extend({
* Clear uploads
*/
clear: function() {
this._uploads = {};
this._knownDirs = {};
},
/**
@ -595,6 +594,19 @@ OC.Uploader.prototype = _.extend({
return null;
},
/**
* Removes an upload from the list of known uploads.
*
* @param {OC.FileUpload} upload the upload to remove.
*/
removeUpload: function(upload) {
if (!upload || !upload.data || !upload.data.uploadId) {
return;
}
delete this._uploads[upload.data.uploadId];
},
showUploadCancelMessage: _.debounce(function() {
OC.Notification.show(t('files', 'Upload cancelled.'), {timeout : 7, type: 'error'});
}, 500),
@ -959,6 +971,8 @@ OC.Uploader.prototype = _.extend({
}
self.log('fail', e, upload);
self.removeUpload(upload);
if (data.textStatus === 'abort') {
self.showUploadCancelMessage();
} else if (status === 412) {
@ -996,6 +1010,8 @@ OC.Uploader.prototype = _.extend({
var that = $(this);
self.log('done', e, upload);
self.removeUpload(upload);
var status = upload.getResponseStatus();
if (status < 200 || status >= 300) {
// trigger fail handler