summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-25 16:37:46 +0100
committerRobin Appelman <icewind@owncloud.com>2014-06-04 16:08:59 +0200
commitda889ff029446119cf6159e75c48ef83be7de7e8 (patch)
treeb88399936d4e4ec24145739db4cc9c1e3e09c833 /lib
parentb5f0a179187bb3f10a939518c6eba72593c1f7a5 (diff)
downloadnextcloud-server-da889ff029446119cf6159e75c48ef83be7de7e8.tar.gz
nextcloud-server-da889ff029446119cf6159e75c48ef83be7de7e8.zip
Added experimental switch to count external storage data in quota
This includes all mountpoints except the Shared one in the used space calculation. Added unit tests for ext storage inclusion in quota calculation
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/view.php8
-rw-r--r--lib/private/helper.php47
2 files changed, 53 insertions, 2 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 0b8d336f260..2e189d12dbd 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -807,7 +807,8 @@ class View {
* get the filesystem info
*
* @param string $path
- * @param boolean $includeMountPoints whether to add mountpoint sizes,
+ * @param boolean|string $includeMountPoints true to add mountpoint sizes,
+ * 'ext' to add only ext storage mount point sizes. Defaults to true.
* defaults to true
* @return \OC\Files\FileInfo|false
*/
@@ -847,10 +848,15 @@ class View {
if ($data and isset($data['fileid'])) {
if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
//add the sizes of other mountpoints to the folder
+ $extOnly = ($includeMountPoints === 'ext');
$mountPoints = Filesystem::getMountPoints($path);
foreach ($mountPoints as $mountPoint) {
$subStorage = Filesystem::getStorage($mountPoint);
if ($subStorage) {
+ // exclude shared storage ?
+ if ($extOnly && $subStorage instanceof \OC\Files\Storage\Shared) {
+ continue;
+ }
$subCache = $subStorage->getCache('');
$rootEntry = $subCache->get('');
$data['size'] += isset($rootEntry['size']) ? $rootEntry['size'] : 0;
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 9ac07bbd3b1..a054fc485a4 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -936,6 +936,8 @@ class OC_Helper {
*/
public static function getStorageInfo($path, $rootInfo = null) {
// return storage info without adding mount points
+ $includeExtStorage = \OC_Config::getValue('quota_include_external_storage', false);
+
if (is_null($rootInfo)) {
$rootInfo = \OC\Files\Filesystem::getFileInfo($path, false);
}
@@ -944,8 +946,20 @@ class OC_Helper {
$used = 0;
}
$quota = 0;
- // TODO: need a better way to get total space from storage
$storage = $rootInfo->getStorage();
+ if ($includeExtStorage && $storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
+ $includeExtStorage = false;
+ }
+ if ($includeExtStorage) {
+ $quota = OC_Util::getUserQuota(\OCP\User::getUser());
+ if ($quota !== \OC\Files\SPACE_UNLIMITED) {
+ // always get free space / total space from root + mount points
+ $path = '';
+ return self::getGlobalStorageInfo();
+ }
+ }
+
+ // TODO: need a better way to get total space from storage
if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
$quota = $storage->getQuota();
}
@@ -967,4 +981,35 @@ class OC_Helper {
return array('free' => $free, 'used' => $used, 'total' => $total, 'relative' => $relative);
}
+
+ /**
+ * Get storage info including all mount points and quota
+ *
+ * @return array
+ */
+ private static function getGlobalStorageInfo() {
+ $quota = OC_Util::getUserQuota(\OCP\User::getUser());
+
+ $rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext');
+ $used = $rootInfo['size'];
+ if ($used < 0) {
+ $used = 0;
+ }
+
+ $total = $quota;
+ $free = $quota - $used;
+
+ if ($total > 0) {
+ if ($quota > 0 && $total > $quota) {
+ $total = $quota;
+ }
+ // prevent division by zero or error codes (negative values)
+ $relative = round(($used / $total) * 10000) / 100;
+ } else {
+ $relative = 0;
+ }
+
+ return array('free' => $free, 'used' => $used, 'total' => $total, 'relative' => $relative);
+
+ }
}