[Pkg-owncloud-commits] [owncloud] 17/69: make sure that we update the unencrypted size for the versions

David Prévot taffit at moszumanska.debian.org
Wed Nov 11 02:04:01 UTC 2015


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

taffit pushed a commit to branch stable8
in repository owncloud.

commit 6d6e5c1b37e6f1ee17da27ce5365a99857e9b4ee
Author: Björn Schießle <bjoern at schiessle.org>
Date:   Wed Nov 4 10:15:28 2015 +0100

    make sure that we update the unencrypted size for the versions
---
 lib/private/files/storage/wrapper/encryption.php | 14 +++-
 tests/lib/files/storage/wrapper/encryption.php   | 96 ++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index d6b7f53..a2bc82e 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -472,6 +472,7 @@ class Encryption extends Wrapper {
 	 * @param bool $preserveMtime
 	 * @param bool $isRename
 	 * @return bool
+	 * @throws \Exception
 	 */
 	private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
 
@@ -479,7 +480,18 @@ class Encryption extends Wrapper {
 		// key from the original file. Just create a 1:1 copy and done
 		if ($this->isVersion($targetInternalPath) ||
 			$this->isVersion($sourceInternalPath)) {
-			return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+			$result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+			if ($result) {
+				$info = $this->getCache('', $sourceStorage)->get($sourceInternalPath);
+				// make sure that we update the unencrypted size for the version
+				if (isset($info['encrypted']) && $info['encrypted'] === true) {
+					$this->updateUnencryptedSize(
+						$this->getFullPath($targetInternalPath),
+						$info['size']
+					);
+				}
+			}
+			return $result;
 		}
 
 		// first copy the keys that we reuse the existing file key on the target location
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index 0954054..2b93aa8 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -560,6 +560,102 @@ class Encryption extends \Test\Files\Storage\Storage {
 	}
 
 	/**
+	 * @dataProvider dataTestCopyBetweenStorageVersions
+	 *
+	 * @param string $sourceInternalPath
+	 * @param string $targetInternalPath
+	 * @param bool $copyResult
+	 * @param bool $encrypted
+	 */
+	public function  testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) {
+
+		$sourceStorage = $this->getMockBuilder('OCP\Files\Storage')
+			->disableOriginalConstructor()
+			->getMock();
+
+		$targetStorage = $this->getMockBuilder('OCP\Files\Storage')
+			->disableOriginalConstructor()
+			->getMock();
+
+		$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
+			->disableOriginalConstructor()->getMock();
+
+		$mountPoint = '/mountPoint';
+
+		/** @var \OC\Files\Storage\Wrapper\Encryption |\PHPUnit_Framework_MockObject_MockObject  $instance */
+		$instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+			->setConstructorArgs(
+				[
+					[
+						'storage' => $targetStorage,
+						'root' => 'foo',
+						'mountPoint' => $mountPoint,
+						'mount' => $this->mount
+					],
+					$this->encryptionManager,
+					$this->util,
+					$this->logger,
+					$this->file,
+					null,
+					$this->keyStore,
+					$this->update,
+					$this->mountManager
+				]
+			)
+			->setMethods(['updateUnencryptedSize', 'getCache'])
+			->getMock();
+
+		$targetStorage->expects($this->once())->method('copyFromStorage')
+			->with($sourceStorage, $sourceInternalPath, $targetInternalPath)
+			->willReturn($copyResult);
+
+		if ($copyResult) {
+			$instance->expects($this->once())->method('getCache')
+				->with('', $sourceStorage)
+				->willReturn($cache);
+			$cache->expects($this->once())->method('get')
+				->with($sourceInternalPath)
+				->willReturn(['encrypted' => $encrypted, 'size' => 42]);
+			if ($encrypted) {
+				$instance->expects($this->once())->method('updateUnencryptedSize')
+					->with($mountPoint . $targetInternalPath, 42);
+			} else {
+				$instance->expects($this->never())->method('updateUnencryptedSize');
+			}
+		} else {
+			$instance->expects($this->never())->method('updateUnencryptedSize');
+		}
+
+		$result = $this->invokePrivate(
+			$instance,
+			'copyBetweenStorage',
+			[
+				$sourceStorage,
+				$sourceInternalPath,
+				$targetInternalPath,
+				false,
+				false
+			]
+		);
+
+		$this->assertSame($copyResult, $result);
+	}
+
+	public function dataTestCopyBetweenStorageVersions() {
+		return [
+			['/files/foo.txt', '/files_versions/foo.txt.768743', true, true],
+			['/files/foo.txt', '/files_versions/foo.txt.768743', true, false],
+			['/files/foo.txt', '/files_versions/foo.txt.768743', false, true],
+			['/files/foo.txt', '/files_versions/foo.txt.768743', false, false],
+			['/files_versions/foo.txt.6487634', '/files/foo.txt', true, true],
+			['/files_versions/foo.txt.6487634', '/files/foo.txt', true, false],
+			['/files_versions/foo.txt.6487634', '/files/foo.txt', false, true],
+			['/files_versions/foo.txt.6487634', '/files/foo.txt', false, false],
+
+		];
+	}
+
+	/**
 	 * @dataProvider dataTestIsVersion
 	 * @param string $path
 	 * @param bool $expected

-- 
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