Skip to content

Commit

Permalink
Merge pull request #9245 from nextcloud/fix-race-condition-when-prepa…
Browse files Browse the repository at this point in the history
…ring-upload-folder

Fix race condition when preparing upload folder
  • Loading branch information
rullzer authored Apr 23, 2018
2 parents a80fcf1 + 375a55b commit 3ff041f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ OC.Uploader.prototype = _.extend({
* Clear uploads
*/
clear: function() {
this._uploads = {};
this._knownDirs = {};
},
/**
Expand All @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3ff041f

Please sign in to comment.