Skip to content

Commit

Permalink
Added config switch for file locking
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored and icewind1991 committed Jun 1, 2015
1 parent c72ea9f commit 2f4f468
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
13 changes: 13 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,19 @@
*/
'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!
Expand Down
60 changes: 60 additions & 0 deletions lib/private/lock/nooplockingprovider.php
Original file line number Diff line number Diff line change
@@ -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
}
}
15 changes: 10 additions & 5 deletions lib/private/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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;
Expand Down Expand Up @@ -422,11 +423,15 @@ public function __construct($webRoot) {
);
});
$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();
});
}

Expand Down

0 comments on commit 2f4f468

Please sign in to comment.