[Pkg-owncloud-commits] [owncloud] 63/134: Return unencrypted_size of folder when queried

David Prévot taffit at moszumanska.debian.org
Fri Apr 18 21:44:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit eacb4b3f3ea7d5b8cf2458b2b9ffd22ec7bb7c3a
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Fri Mar 7 11:25:29 2014 +0100

    Return unencrypted_size of folder when queried
    
    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         |  7 +++++++
 apps/files_encryption/tests/proxy.php       | 20 ++++++++++++++++++++
 lib/private/files/storage/wrapper/quota.php |  5 +++++
 tests/lib/files/storage/wrapper/quota.php   | 16 ++++++++++++++++
 4 files changed, 48 insertions(+)

diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 148b7bc..22b06da 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -339,6 +339,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;
 		}
 
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index 51cc0b7..647ee95 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -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);
+
+	}
+
 }
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index a430e3e..7409414 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -27,6 +27,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;
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 87bafb6..e9727ba 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -50,6 +50,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+');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list