Skip to content

Commit

Permalink
Defer quota check in web UI when overwriting shared file
Browse files Browse the repository at this point in the history
When receiving a shared file, the quota for that file counts in the
owner's storage, not the current user's storage.

To make it possible to overwrite the file even when the current user
doesn't have enough space, the quota check is deferred for such files.
  • Loading branch information
Vincent Petry committed Feb 17, 2016
1 parent 8f96ef1 commit ceaefc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
8 changes: 6 additions & 2 deletions apps/files/ajax/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@
$maxHumanFileSize = OCP\Util::humanFileSize($maxUploadFileSize);

$totalSize = 0;
foreach ($files['size'] as $size) {
$totalSize += $size;
$isReceivedShare = \OC::$server->getRequest()->getParam('isReceivedShare', false) === 'true';
// defer quota check for received shares
if (!$isReceivedShare) {
foreach ($files['size'] as $size) {
$totalSize += $size;
}
}
if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'),
Expand Down
43 changes: 36 additions & 7 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,26 @@ OC.Upload = {
$('#file_upload_start').trigger(new $.Event('resized'));
},

/**
* Returns whether the given file is known to be a received shared file
*
* @param {Object} file file
* @return {bool} true if the file is a shared file
*/
_isReceivedSharedFile: function(file) {
if (!window.FileList) {
return false;
}
var $tr = window.FileList.findFileEl(file.name);
if (!$tr.length) {
return false;
}

return ($tr.attr('data-mounttype') === 'shared-root' && $tr.attr('data-mime') !== 'httpd/unix-directory');
},

init: function() {
var self = this;
if ( $('#file_upload_start').exists() ) {
var file_upload_param = {
dropZone: $('#content'), // restrict dropZone to content div
Expand Down Expand Up @@ -341,10 +360,15 @@ OC.Upload = {
}
}

// add size
selection.totalBytes += file.size;
// update size of biggest file
selection.biggestFileBytes = Math.max(selection.biggestFileBytes, file.size);
// only count if we're not overwriting an existing shared file
if (self._isReceivedSharedFile(file)) {
file.isReceivedShare = true;
} else {
// add size
selection.totalBytes += file.size;
// update size of biggest file
selection.biggestFileBytes = Math.max(selection.biggestFileBytes, file.size);
}

// check PHP upload limit against biggest file
if (selection.biggestFileBytes > $('#upload_limit').val()) {
Expand Down Expand Up @@ -430,11 +454,16 @@ OC.Upload = {
fileDirectory = data.files[0].relativePath;
}

addFormData(data.formData, {
var params = {
requesttoken: oc_requesttoken,
dir: data.targetDir || FileList.getCurrentDirectory(),
file_directory: fileDirectory
});
file_directory: fileDirectory,
};
if (data.files[0].isReceivedShare) {
params.isReceivedShare = true;
}

addFormData(data.formData, params);
},
fail: function(e, data) {
OC.Upload.log('fail', e, data);
Expand Down

0 comments on commit ceaefc2

Please sign in to comment.