[Pkg-owncloud-commits] [owncloud] 221/457: Added config switch for file locking

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:11 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 2f4f468399d316157979f747d2418fb5cff8d3e0
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Thu May 21 16:11:10 2015 +0200

    Added config switch for file locking
---
 config/config.sample.php                 | 13 +++++++
 lib/private/lock/nooplockingprovider.php | 60 ++++++++++++++++++++++++++++++++
 lib/private/server.php                   | 15 +++++---
 3 files changed, 83 insertions(+), 5 deletions(-)

diff --git a/config/config.sample.php b/config/config.sample.php
index ed86dd9..a9fafe7 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -1026,6 +1026,19 @@ $CONFIG = array(
  */
 'max_filesize_animated_gifs_public_sharing' => 10,
 
+
+/**
+ * Enables the EXPERIMENTAL file locking.
+ * This is disabled by default as it is experimental.
+ *
+ * Prevents concurrent processes to access the same files
+ * at the same time. Can help prevent side effects that would
+ * be caused by concurrent operations.
+ *
+ * WARNING: EXPERIMENTAL
+ */
+'filelocking.enabled' => false,
+
 /**
  * This entry is just here to show a warning in case somebody copied the sample
  * configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION!
diff --git a/lib/private/lock/nooplockingprovider.php b/lib/private/lock/nooplockingprovider.php
new file mode 100644
index 0000000..0ca8edb
--- /dev/null
+++ b/lib/private/lock/nooplockingprovider.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @author Vincent Petry <pvince81 at owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Lock;
+
+use OCP\Lock\ILockingProvider;
+
+/**
+ * Locking provider that does nothing.
+ *
+ * To be used when locking is disabled.
+ */
+class NoopLockingProvider implements ILockingProvider {
+
+    /**
+     * {@inheritdoc}
+     */
+	public function isLocked($path, $type) {
+		return false;
+	}
+
+    /**
+     * {@inheritdoc}
+     */
+	public function acquireLock($path, $type) {
+		// do nothing
+	}
+
+	/**
+     * {@inheritdoc}
+	 */
+	public function releaseLock($path, $type) {
+		// do nothing
+	}
+
+	/**
+	 * release all lock acquired by this instance
+	 */
+	public function releaseAll() {
+		// do nothing
+	}
+}
diff --git a/lib/private/server.php b/lib/private/server.php
index 900d754..88f57e7 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -44,6 +44,7 @@ use OC\Diagnostics\NullQueryLogger;
 use OC\Diagnostics\EventLogger;
 use OC\Diagnostics\QueryLogger;
 use OC\Lock\MemcacheLockingProvider;
+use OC\Lock\NoopLockingProvider;
 use OC\Mail\Mailer;
 use OC\Memcache\ArrayCache;
 use OC\Http\Client\ClientService;
@@ -422,11 +423,15 @@ class Server extends SimpleContainer implements IServerContainer {
 			);
 		});
 		$this->registerService('LockingProvider', function (Server $c) {
-			/** @var \OC\Memcache\Factory $memcacheFactory */
-			$memcacheFactory = $c->getMemCacheFactory();
-			return new MemcacheLockingProvider(
-				$memcacheFactory->createDistributed('lock')
-			);
+			if ($c->getConfig()->getSystemValue('filelocking.enabled', false)) {
+				/** @var \OC\Memcache\Factory $memcacheFactory */
+				$memcacheFactory = $c->getMemCacheFactory();
+				$memcache = $memcacheFactory->createDistributed('lock');
+				if (!($memcache instanceof \OC\Memcache\Null)) {
+					return new MemcacheLockingProvider($memcache);
+				}
+			}
+			return new NoopLockingProvider();
 		});
 	}
 

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