diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-05-21 16:11:10 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-06-01 13:22:56 +0200 |
commit | 2f4f468399d316157979f747d2418fb5cff8d3e0 (patch) | |
tree | a29a1e0b6d5438c4e2c178f24ea0788fdbcc8829 | |
parent | c72ea9f7d72d3ab22ff56195235808b17cecb0ba (diff) | |
download | nextcloud-server-2f4f468399d316157979f747d2418fb5cff8d3e0.tar.gz nextcloud-server-2f4f468399d316157979f747d2418fb5cff8d3e0.zip |
Added config switch for file locking
-rw-r--r-- | config/config.sample.php | 13 | ||||
-rw-r--r-- | lib/private/lock/nooplockingprovider.php | 60 | ||||
-rw-r--r-- | 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 ed86dd94131..a9fafe7b4f1 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 00000000000..0ca8edb4d00 --- /dev/null +++ b/lib/private/lock/nooplockingprovider.php @@ -0,0 +1,60 @@ +<?php +/** + * @author Vincent Petry <pvince81@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 900d754012c..88f57e73a39 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(); }); } |