[Pkg-owncloud-commits] [owncloud] 185/215: allow getting the path from the lockedexception

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:48 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 ba7d221cffab4b42871e5926dd6c3e0a2d2b98dc
Author: Robin Appelman <icewind at owncloud.com>
Date:   Thu Apr 30 14:16:09 2015 +0200

    allow getting the path from the lockedexception
---
 lib/private/lock/memcachelockingprovider.php |  4 ++--
 lib/public/lock/lockedexception.php          | 21 +++++++++++++++++++++
 tests/lib/lock/lockingprovider.php           | 19 +++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/lib/private/lock/memcachelockingprovider.php b/lib/private/lock/memcachelockingprovider.php
index 43fdf70..9c8c723 100644
--- a/lib/private/lock/memcachelockingprovider.php
+++ b/lib/private/lock/memcachelockingprovider.php
@@ -62,12 +62,12 @@ class MemcacheLockingProvider implements ILockingProvider {
 	public function acquireLock($path, $type) {
 		if ($type === self::LOCK_SHARED) {
 			if (!$this->memcache->inc($path)) {
-				throw new LockedException($path . ' is locked');
+				throw new LockedException($path);
 			}
 		} else {
 			$this->memcache->add($path, 0);
 			if (!$this->memcache->cas($path, 0, 'exclusive')) {
-				throw new LockedException($path . ' is locked');
+				throw new LockedException($path);
 			}
 		}
 	}
diff --git a/lib/public/lock/lockedexception.php b/lib/public/lock/lockedexception.php
index 4c0ca9b..87f7164 100644
--- a/lib/public/lock/lockedexception.php
+++ b/lib/public/lock/lockedexception.php
@@ -22,4 +22,25 @@
 namespace OCP\Lock;
 
 class LockedException extends \Exception {
+	/**
+	 * @var string
+	 */
+	private $path;
+
+	/**
+	 * LockedException constructor.
+	 *
+	 * @param string $path
+	 */
+	public function __construct($path) {
+		parent::__construct($path . ' is locked');
+		$this->path = $path;
+	}
+
+	/**
+	 * @return string
+	 */
+	public function getPath() {
+		return $this->path;
+	}
 }
diff --git a/tests/lib/lock/lockingprovider.php b/tests/lib/lock/lockingprovider.php
index e7b8028..08d879d 100644
--- a/tests/lib/lock/lockingprovider.php
+++ b/tests/lib/lock/lockingprovider.php
@@ -22,6 +22,7 @@
 namespace Test\Lock;
 
 use OCP\Lock\ILockingProvider;
+use OCP\Lock\LockedException;
 use Test\TestCase;
 
 abstract class LockingProvider extends TestCase {
@@ -115,4 +116,22 @@ abstract class LockingProvider extends TestCase {
 		$this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE));
 		$this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
 	}
+
+	public function testLockedExceptionHasPathForShared() {
+		try {
+			$this->testSharedLockAfterExclusive();
+			$this->fail('Expected locked exception');
+		} catch (LockedException $e) {
+			$this->assertEquals('foo', $e->getPath());
+		}
+	}
+
+	public function testLockedExceptionHasPathForExclusive() {
+		try {
+			$this->testExclusiveLockAfterShared();
+			$this->fail('Expected locked exception');
+		} catch (LockedException $e) {
+			$this->assertEquals('foo', $e->getPath());
+		}
+	}
 }

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