]> source.dussan.org Git - nextcloud-server.git/commitdiff
Now using the "Home" storage detection approach for quota
authorVincent Petry <pvince81@owncloud.com>
Thu, 21 Nov 2013 11:17:47 +0000 (12:17 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 21 Nov 2013 11:17:47 +0000 (12:17 +0100)
To find out whether to apply a quota, we now try and detect whether the
storage to wrap is a "Home" storage.

lib/private/files/storage/home.php
lib/private/util.php

index b4ceb8f4f9bab60793fc47ac223a7da065cfe52d..1c2a682f197e7a789a8fa81d88f6e90cf127399a 100644 (file)
@@ -22,6 +22,12 @@ class Home extends Local {
         */
        protected $user;
 
+       /**
+        * @brief Construct a Home storage instance
+        * @param array $arguments array with "user" containing the
+        * storage owner and "legacy" containing "true" if the storage is
+        * a legacy storage with "local::" URL instead of the new "home::" one.
+        */
        public function __construct($arguments) {
                $this->user = $arguments['user'];
                $datadir = $this->user->getHome();
@@ -40,10 +46,21 @@ class Home extends Local {
                return $this->id;
        }
 
+       /**
+        * @return \OC\Files\Cache\HomeCache
+        */
        public function getCache($path = '') {
                if (!isset($this->cache)) {
                        $this->cache = new \OC\Files\Cache\HomeCache($this);
                }
                return $this->cache;
        }
+
+       /**
+        * @brief Returns the owner of this home storage
+        * @return \OC\User\User owner of this home storage
+        */
+       public function getUser() {
+               return $this->user;
+       }
 }
index 88f1f197b5d8ba6ff009ee612342cd5138c46117..959d36a89e9e8e423a104502408eda91f4735b18 100755 (executable)
@@ -57,21 +57,11 @@ class OC_Util {
                                // set up quota for home storages, even for other users
                                // which can happen when using sharing
 
-                               if (strlen($mountPoint) > 1) {
-                                       // the user name will be extracted from the mountpoint
-                                       // with the format '/username/' (no suffix)
-                                       $user = null;
-                                       // find second separator
-                                       $nextSepPos = strpos($mountPoint, '/', 1);
-                                       // next separator is the last one, format matches
-                                       if ($nextSepPos === strlen($mountPoint) - 1) {
-                                               $user = substr($mountPoint, 1, $nextSepPos - 1);
-                                       }
-                                       if ($user) {
-                                               $quota = OC_Util::getUserQuota($user);
-                                               if ($quota !== \OC\Files\SPACE_UNLIMITED) {
-                                                       return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
-                                               }
+                               if ($storage instanceof \OC\Files\Storage\Home) {
+                                       $user = $storage->getUser()->getUID();
+                                       $quota = OC_Util::getUserQuota($user);
+                                       if ($quota !== \OC\Files\SPACE_UNLIMITED) {
+                                               return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
                                        }
                                }