]> source.dussan.org Git - nextcloud-server.git/commitdiff
Detect storage full when doing cross storage copy/move
authorRobin Appelman <icewind@owncloud.com>
Thu, 5 Mar 2015 10:49:15 +0000 (11:49 +0100)
committerRobin Appelman <icewind@owncloud.com>
Mon, 13 Apr 2015 13:13:03 +0000 (15:13 +0200)
lib/private/files/storage/wrapper/quota.php

index 3c0fda98dad08d49501f03fad35ea752eb8ba22a..92d749a814fd5c8eaffb891b031fba7d3ae09198 100644 (file)
@@ -55,9 +55,14 @@ class Quota extends Wrapper {
 
        /**
         * @param string $path
+        * @param \OC\Files\Storage\Storage $storage
         */
-       protected function getSize($path) {
-               $cache = $this->getCache();
+       protected function getSize($path, $storage = null) {
+               if (is_null($storage)) {
+                       $cache = $this->getCache();
+               } else {
+                       $cache = $storage->getCache();
+               }
                $data = $cache->get($path);
                if (is_array($data) and isset($data['size'])) {
                        return $data['size'];
@@ -141,4 +146,34 @@ class Quota extends Wrapper {
                        return $source;
                }
        }
+
+       /**
+        * @param \OCP\Files\Storage $sourceStorage
+        * @param string $sourceInternalPath
+        * @param string $targetInternalPath
+        * @return bool
+        */
+       public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+               $free = $this->free_space('');
+               if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
+                       return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * @param \OCP\Files\Storage $sourceStorage
+        * @param string $sourceInternalPath
+        * @param string $targetInternalPath
+        * @return bool
+        */
+       public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+               $free = $this->free_space('');
+               if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
+                       return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+               } else {
+                       return false;
+               }
+       }
 }