From 3c1ab66edac1ba2f1b398c859cd933c410ea3d8d Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Mon, 27 Jan 2014 15:56:57 +0100
Subject: [PATCH] Reuse the calculated free_space in buildFileStorageStatistics

---
 apps/files/lib/helper.php | 8 ++++----
 lib/private/helper.php    | 9 ++++++---
 lib/public/util.php       | 7 ++++---
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index eaff28178e..87939d2692 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -5,14 +5,14 @@ namespace OCA\Files;
 class Helper
 {
 	public static function buildFileStorageStatistics($dir) {
+		// information about storage capacities
+		$storageInfo = \OC_Helper::getStorageInfo($dir);
+
 		$l = new \OC_L10N('files');
-		$maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir);
+		$maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
 		$maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize);
 		$maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize;
 
-		// information about storage capacities
-		$storageInfo = \OC_Helper::getStorageInfo($dir);
-
 		return array('uploadMaxFilesize' => $maxUploadFilesize,
 					 'maxHumanFilesize'  => $maxHumanFilesize,
 					 'usedSpacePercent'  => (int)$storageInfo['relative']);
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 1c8d01c141..12784c9a5e 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -824,13 +824,16 @@ class OC_Helper {
 	/**
 	 * @brief calculates the maximum upload size respecting system settings, free space and user quota
 	 *
-	 * @param $dir the current folder where the user currently operates
+	 * @param string $dir the current folder where the user currently operates
+	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
 	 * @return number of bytes representing
 	 */
-	public static function maxUploadFilesize($dir) {
+	public static function maxUploadFilesize($dir, $freeSpace = null) {
 		$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
 		$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
-		$freeSpace = \OC\Files\Filesystem::free_space($dir);
+		if (is_null($freeSpace)) {
+			$freeSpace = \OC\Files\Filesystem::free_space($dir);
+		}
 		if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
 			$maxUploadFilesize = \OC\Files\SPACE_UNLIMITED;
 		} elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
diff --git a/lib/public/util.php b/lib/public/util.php
index 6317f10a66..52874bcc95 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -456,10 +456,11 @@ class Util {
 	/**
 	 * calculates the maximum upload size respecting system settings, free space and user quota
 	 *
-	 * @param $dir the current folder where the user currently operates
+	 * @param string $dir the current folder where the user currently operates
+	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
 	 * @return number of bytes representing
 	 */
-	public static function maxUploadFilesize($dir) {
-		return \OC_Helper::maxUploadFilesize($dir);
+	public static function maxUploadFilesize($dir, $free = null) {
+		return \OC_Helper::maxUploadFilesize($dir, $free);
 	}
 }
-- 
GitLab