]> source.dussan.org Git - nextcloud-server.git/commitdiff
Return unencrypted_size of folder when queried
authorVincent Petry <pvince81@owncloud.com>
Fri, 7 Mar 2014 10:25:29 +0000 (11:25 +0100)
committerVincent Petry <pvince81@owncloud.com>
Fri, 7 Mar 2014 13:59:09 +0000 (14:59 +0100)
This fixes the "used space" to be based on the unencrypted size, not
encrypted size, to be consistent with how quota/space is handled when
encryption is enabled

apps/files_encryption/lib/proxy.php
apps/files_encryption/tests/proxy.php
lib/private/files/storage/wrapper/quota.php
tests/lib/files/storage/wrapper/quota.php

index a2d42c22c13d239920a38b48f05cac7e9aa4a9f7..b7e1599c1fe9518139dd15a3b417579a5cc18f02 100644 (file)
@@ -340,6 +340,13 @@ class Proxy extends \OC_FileProxy {
 
                // if path is a folder do nothing
                if ($view->is_dir($path)) {
+                       $proxyState = \OC_FileProxy::$enabled;
+                       \OC_FileProxy::$enabled = false;
+                       $fileInfo = $view->getFileInfo($path);
+                       \OC_FileProxy::$enabled = $proxyState;
+                       if ($fileInfo['unencrypted_size'] > 0) {
+                               return $fileInfo['unencrypted_size'];
+                       }
                        return $size;
                }
 
index 51cc0b795e38bdd3d7c9aede64417d3b3ede5d87..647ee955eb1ac7d763f1504956c725459af475ce 100644 (file)
@@ -112,4 +112,24 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
 
        }
 
+       function testPostFileSizeWithDirectory() {
+
+               $this->view->file_put_contents($this->filename, $this->data);
+
+               \OC_FileProxy::$enabled = false;
+
+               // get root size, must match the file's unencrypted size
+               $unencryptedSize = $this->view->filesize('');
+
+               \OC_FileProxy::$enabled = true;
+
+               $encryptedSize = $this->view->filesize('');
+
+               $this->assertTrue($encryptedSize !== $unencryptedSize);
+
+               // cleanup
+               $this->view->unlink($this->filename);
+
+       }
+
 }
index 26c952e694ac6aa8793823ca4a21dccb4ffe6089..ea612735477db7435a48cf0514d4498c2cef63b7 100644 (file)
@@ -36,6 +36,11 @@ class Quota extends Wrapper {
                $cache = $this->getCache();
                $data = $cache->get($path);
                if (is_array($data) and isset($data['size'])) {
+                       if (isset($data['unencrypted_size'])
+                               && $data['unencrypted_size'] > 0
+                       ) {
+                               return $data['unencrypted_size'];
+                       }
                        return $data['size'];
                } else {
                        return \OC\Files\SPACE_NOT_COMPUTED;
index 43eae78415df0c921bea7a6a5d3ccb4ec13a2a21..bd2c69a7396a000aff04963ac7072472a5664fcf 100644 (file)
@@ -53,6 +53,22 @@ class Quota extends \Test\Files\Storage\Storage {
                $this->assertEquals(9, $instance->free_space(''));
        }
 
+       public function testFreeSpaceWithUsedSpace() {
+               $instance = $this->getLimitedStorage(9);
+               $instance->getCache()->put(
+                       '', array('size' => 3, 'unencrypted_size' => 0)
+               );
+               $this->assertEquals(6, $instance->free_space(''));
+       }
+
+       public function testFreeSpaceWithUsedSpaceAndEncryption() {
+               $instance = $this->getLimitedStorage(9);
+               $instance->getCache()->put(
+                       '', array('size' => 7, 'unencrypted_size' => 3)
+               );
+               $this->assertEquals(6, $instance->free_space(''));
+       }
+
        public function testFWriteNotEnoughSpace() {
                $instance = $this->getLimitedStorage(9);
                $stream = $instance->fopen('foo', 'w+');