summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-02-04 15:58:16 +0100
committerLukas Reschke <lukas@owncloud.com>2015-02-04 15:58:16 +0100
commitcc80ce70b41d938ba5df512509a589804417a9d7 (patch)
tree642f38a4cce2a42f14310cd8a7352d14332df693 /apps/files
parent486f49ed72970276462f09074829576588352b2a (diff)
downloadnextcloud-server-cc80ce70b41d938ba5df512509a589804417a9d7.tar.gz
nextcloud-server-cc80ce70b41d938ba5df512509a589804417a9d7.zip
Catch exception properly
`\OCA\Files\Helper::buildFileStorageStatistics` might throw an exception from `OC_Helper::getStorageInfo`, previously this lead to a uncatched exception being thrown when invoking this methods. This was user triggable by for example calling `/index.php/apps/files/ajax/delete.php` with a not existing dir (for example `dir=asdf/../&allfiles=true`)
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/ajax/delete.php7
-rw-r--r--apps/files/lib/helper.php19
2 files changed, 18 insertions, 8 deletions
diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php
index 61caa7618da..1a810f6954c 100644
--- a/apps/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -36,7 +36,12 @@ foreach ($files as $file) {
}
// get array with updated storage stats (e.g. max file size) after upload
-$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
+try {
+ $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
+} catch(\OCP\Files\NotFoundException $e) {
+ OCP\JSON::error(['data' => ['message' => 'File not found']]);
+ return;
+}
if ($success) {
OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index 84b1a0f1662..bcca6f0a276 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -13,21 +13,26 @@ use OCP\Files\FileInfo;
/**
* Helper class for manipulating file information
*/
-class Helper
-{
+class Helper {
+ /**
+ * @param string $dir
+ * @return array
+ * @throws \OCP\Files\NotFoundException
+ */
public static function buildFileStorageStatistics($dir) {
// information about storage capacities
$storageInfo = \OC_Helper::getStorageInfo($dir);
-
$l = new \OC_L10N('files');
$maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
$maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
$maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize));
- return array('uploadMaxFilesize' => $maxUploadFileSize,
- 'maxHumanFilesize' => $maxHumanFileSize,
- 'freeSpace' => $storageInfo['free'],
- 'usedSpacePercent' => (int)$storageInfo['relative']);
+ return [
+ 'uploadMaxFilesize' => $maxUploadFileSize,
+ 'maxHumanFilesize' => $maxHumanFileSize,
+ 'freeSpace' => $storageInfo['free'],
+ 'usedSpacePercent' => (int)$storageInfo['relative']
+ ];
}
/**