From 2ae1ad23b0722f827ca14bcac889dbfb9b6bf5d6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 7 Mar 2013 15:48:10 +0100 Subject: [PATCH 1/2] Offer download of whole shared dir only if it does not exceed zip input limit --- apps/files_sharing/public.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index e345b91e29..1da972ad7e 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -141,7 +141,9 @@ if (isset($path)) { OCP\Util::addscript('files', 'keyboardshortcuts'); $files = array(); $rootLength = strlen($basePath) + 1; + $totalSize = 0; foreach (\OC\Files\Filesystem::getDirectoryContent($path) as $i) { + $totalSize += $i['size']; $i['date'] = OCP\Util::formatDate($i['mtime']); if ($i['type'] == 'file') { $fileinfo = pathinfo($i['name']); @@ -188,7 +190,9 @@ if (isset($path)) { $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $folder->assign('usedSpacePercent', 0); $tmpl->assign('folder', $folder->fetchPage()); - $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); + $allowZip = OCP\Config::getSystemValue('allowZipDownload', true) + && $totalSize <= OCP\Config::getSystemValue('maxZipInputSize', OCP\Util::computerFileSize('800 MB')); + $tmpl->assign('allowZipDownload', intval($allowZip)); $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } else { From f4a326173e978e4b3491b23d27f8dcafdfbaff09 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 8 Mar 2013 19:21:06 +0100 Subject: [PATCH 2/2] fix foldersize check to validate zip input size --- lib/files.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/files.php b/lib/files.php index b594b78c4b..059c465792 100644 --- a/lib/files.php +++ b/lib/files.php @@ -212,12 +212,18 @@ class OC_Files { $zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB')); if ($zipLimit > 0) { $totalsize = 0; - if (is_array($files)) { - foreach ($files as $file) { - $totalsize += \OC\Files\Filesystem::filesize($dir . '/' . $file); + if(!is_array($files)) { + $files = array($files); + } + foreach ($files as $file) { + $path = $dir . '/' . $file; + if(\OC\Files\Filesystem::is_dir($path)) { + foreach (\OC\Files\Filesystem::getDirectoryContent($path) as $i) { + $totalsize += $i['size']; + } + } else { + $totalsize += \OC\Files\Filesystem::filesize($path); } - } else { - $totalsize += \OC\Files\Filesystem::filesize($dir . '/' . $files); } if ($totalsize > $zipLimit) { $l = OC_L10N::get('lib');