[Pkg-owncloud-commits] [owncloud] 79/131: fix mount point detection

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 15:58:35 UTC 2015


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

taffit pushed a commit to annotated tag v8.1.1
in repository owncloud.

commit dc6cc57e11559b0a8afd4223c38f22a445b1f68f
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Mon Jul 20 16:00:33 2015 +0200

    fix mount point detection
---
 apps/encryption/lib/migration.php           |  8 +--
 apps/encryption/tests/lib/MigrationTest.php | 77 ++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/apps/encryption/lib/migration.php b/apps/encryption/lib/migration.php
index 0903587..e6887e8 100644
--- a/apps/encryption/lib/migration.php
+++ b/apps/encryption/lib/migration.php
@@ -283,7 +283,7 @@ class Migration {
 						$this->renameFileKeys($user, $path . '/' . $file, $trash);
 					} else {
 						$target = $this->getTargetDir($user, $path, $file, $trash);
-						if ($target) {
+						if ($target !== false) {
 							$this->createPathForKeys(dirname($target));
 							$this->view->rename($user . '/' . $path . '/' . $file, $target);
 						} else {
@@ -303,6 +303,7 @@ class Migration {
 	 * get system mount points
 	 * wrap static method so that it can be mocked for testing
 	 *
+	 * @internal
 	 * @return array
 	 */
 	protected function getSystemMountPoints() {
@@ -329,10 +330,11 @@ class Migration {
 
 		if ($user === '') {
 			// for system wide mounts we need to check if the mount point really exists
-			$normalized = trim($filePath, '/');
+			$normalized = \OC\Files\Filesystem::normalizePath($filePath);
 			$systemMountPoints = $this->getSystemMountPoints();
 			foreach ($systemMountPoints as $mountPoint) {
-				if (strpos($normalized, $mountPoint['mountpoint']) === 0)
+				$normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']) . '/';
+				if (strpos($normalized, $normalizedMountPoint) === 0)
 					return $targetDir;
 			}
 		} else if ($trash === false && $this->view->file_exists('/' . $user. '/files/' . $filePath)) {
diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php
index a83909a..6742de5 100644
--- a/apps/encryption/tests/lib/MigrationTest.php
+++ b/apps/encryption/tests/lib/MigrationTest.php
@@ -179,7 +179,6 @@ class MigrationTest extends \Test\TestCase {
 		$m->expects($this->any())->method('getSystemMountPoints')
 			->willReturn([['mountpoint' => 'folder1'], ['mountpoint' => 'folder2']]);
 
-		//$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
 		$m->reorganizeFolderStructure();
 		// even if it runs twice folder should always move only once
 		$m->reorganizeFolderStructure();
@@ -450,4 +449,80 @@ class MigrationTest extends \Test\TestCase {
 		$this->assertSame(19, count($result));
 	}
 
+	/**
+	 * @dataProvider dataTestGetTargetDir
+	 */
+	public function testGetTargetDir($user, $keyPath, $filename, $trash, $systemMounts, $expected) {
+
+		$updater = $this->getMockBuilder('\OC\Files\Cache\Updater')
+			->disableOriginalConstructor()->getMock();
+		$view = $this->getMockBuilder('\OC\Files\View')
+			->disableOriginalConstructor()->getMock();
+		$view->expects($this->any())->method('file_exists')->willReturn(true);
+		$view->expects($this->any())->method('getUpdater')->willReturn($updater);
+
+
+		$m = $this->getMockBuilder('OCA\Encryption\Migration')
+			->setConstructorArgs(
+				[
+					\OC::$server->getConfig(),
+					$view,
+					\OC::$server->getDatabaseConnection(),
+					$this->logger
+				]
+			)->setMethods(['getSystemMountPoints'])->getMock();
+
+		$m->expects($this->any())->method('getSystemMountPoints')
+			->willReturn($systemMounts);
+
+		$this->assertSame($expected,
+			$this->invokePrivate($m, 'getTargetDir', [$user, $keyPath, $filename, $trash])
+		);
+	}
+
+	public function dataTestGetTargetDir() {
+		return [
+			[
+				'user1',
+				'/files_encryption/keys/foo/bar.txt',
+				'user1.shareKey',
+				false,
+				[],
+				'user1/files_encryption/keys/files/foo/bar.txt/OC_DEFAULT_MODULE/user1.shareKey'
+			],
+			[
+				'user1',
+				'/files_trashbin/keys/foo/bar.txt',
+				'user1.shareKey',
+				true,
+				[],
+				'user1/files_encryption/keys/files_trashbin/foo/bar.txt/OC_DEFAULT_MODULE/user1.shareKey'
+			],
+			[
+				'',
+				'/files_encryption/keys/foo/bar.txt',
+				'user1.shareKey',
+				false,
+				[['mountpoint' => 'foo']],
+				'/files_encryption/keys/files/foo/bar.txt/OC_DEFAULT_MODULE/user1.shareKey'
+			],
+			[
+				'',
+				'/files_encryption/keys/foo/bar.txt',
+				'user1.shareKey',
+				false,
+				[['mountpoint' => 'foobar']],
+				false
+			],
+			[
+				'',
+				'/files_encryption/keys/foobar/bar.txt',
+				'user1.shareKey',
+				false,
+				[['mountpoint' => 'foo']],
+				false
+			]
+		];
+	}
+
 }

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