[Pkg-owncloud-commits] [owncloud] 432/457: Normalize path in View's lock methods

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:07:02 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 102c6ffc41ad6fb70b07776b80b4c53528a6abc8
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Tue Jun 16 11:40:27 2015 +0200

    Normalize path in View's lock methods
---
 lib/private/files/view.php |  9 +++++----
 tests/lib/files/view.php   | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 1d4654e..39e2fe6 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1683,6 +1683,7 @@ class View {
 	 */
 	private function lockPath($path, $type) {
 		$absolutePath = $this->getAbsolutePath($path);
+		$absolutePath = Filesystem::normalizePath($absolutePath);
 		if (!$this->shouldLockFile($absolutePath)) {
 			return false;
 		}
@@ -1717,6 +1718,7 @@ class View {
 	 */
 	public function changeLock($path, $type) {
 		$absolutePath = $this->getAbsolutePath($path);
+		$absolutePath = Filesystem::normalizePath($absolutePath);
 		if (!$this->shouldLockFile($absolutePath)) {
 			return false;
 		}
@@ -1750,6 +1752,7 @@ class View {
 	 */
 	private function unlockPath($path, $type) {
 		$absolutePath = $this->getAbsolutePath($path);
+		$absolutePath = Filesystem::normalizePath($absolutePath);
 		if (!$this->shouldLockFile($absolutePath)) {
 			return false;
 		}
@@ -1774,9 +1777,8 @@ class View {
 	 * @return bool False if the path is excluded from locking, true otherwise
 	 */
 	public function lockFile($path, $type) {
-		$path = '/' . trim($path, '/');
-
 		$absolutePath = $this->getAbsolutePath($path);
+		$absolutePath = Filesystem::normalizePath($absolutePath);
 		if (!$this->shouldLockFile($absolutePath)) {
 			return false;
 		}
@@ -1799,9 +1801,8 @@ class View {
 	 * @return bool False if the path is excluded from locking, true otherwise
 	 */
 	public function unlockFile($path, $type) {
-		$path = rtrim($path, '/');
-
 		$absolutePath = $this->getAbsolutePath($path);
+		$absolutePath = Filesystem::normalizePath($absolutePath);
 		if (!$this->shouldLockFile($absolutePath)) {
 			return false;
 		}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 63d136b..dcdebfd 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -1208,4 +1208,26 @@ class View extends \Test\TestCase {
 		$view = new \OC\Files\View();
 		$view->getPathRelativeToFiles($path);
 	}
+
+	public function testChangeLock() {
+		$view = new \OC\Files\View('/testuser/files/');
+		$storage = new Temporary(array());
+		\OC\Files\Filesystem::mount($storage, [], '/');
+
+		$view->lockFile('/test/sub', ILockingProvider::LOCK_SHARED);
+		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
+		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
+
+		$view->changeLock('//test/sub', ILockingProvider::LOCK_EXCLUSIVE);
+		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
+
+		$view->changeLock('test/sub', ILockingProvider::LOCK_SHARED);
+		$this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
+
+		$view->unlockFile('/test/sub/', ILockingProvider::LOCK_SHARED);
+
+		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED));
+		$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
+
+	}
 }

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