Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-04 22:25:53 +0300
committerC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-04 22:25:53 +0300
commit0c03e7c384af38d63b16e02f4f2a9e6e80db40a8 (patch)
tree05cb163ae9bacb3737d8fb12e3b7a979f637a3f0
parentbf9be4b2c83b94d049b1885ebf14a9add5834da6 (diff)
parent12e006c1f5266a7f3dfbed3e9dbd3f22825e5712 (diff)
Merge pull request #22868 from owncloud/stable8.2-backport-22865
[stable8.2] Run cleanup of expired DB file locks to background job
-rw-r--r--apps/files/appinfo/info.xml2
-rw-r--r--apps/files/appinfo/install.php22
-rw-r--r--apps/files/appinfo/update.php2
-rw-r--r--apps/files/lib/backgroundjob/cleanupfilelocks.php57
-rw-r--r--lib/private/lock/dblockingprovider.php26
5 files changed, 93 insertions, 16 deletions
diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml
index a7c3968cb8f..5227b2f044a 100644
--- a/apps/files/appinfo/info.xml
+++ b/apps/files/appinfo/info.xml
@@ -8,7 +8,7 @@
<shipped>true</shipped>
<standalone/>
<default_enable/>
- <version>1.2.0</version>
+ <version>1.2.1</version>
<types>
<filesystem/>
</types>
diff --git a/apps/files/appinfo/install.php b/apps/files/appinfo/install.php
new file mode 100644
index 00000000000..0815ff2524e
--- /dev/null
+++ b/apps/files/appinfo/install.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, 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/>
+ *
+ */
+
+\OC::$server->getJobList()->add('OCA\Files\BackgroundJob\CleanupFileLocks');
diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php
index 6084435fa5a..0da6ad04911 100644
--- a/apps/files/appinfo/update.php
+++ b/apps/files/appinfo/update.php
@@ -104,3 +104,5 @@ if ($installedVersion === '1.1.9' && (
if(defined('DEBUG') && DEBUG === true) {
\OC::$server->getConfig()->setSystemValue('debug', true);
}
+
+\OC::$server->getJobList()->add('OCA\Files\BackgroundJob\CleanupFileLocks');
diff --git a/apps/files/lib/backgroundjob/cleanupfilelocks.php b/apps/files/lib/backgroundjob/cleanupfilelocks.php
new file mode 100644
index 00000000000..b5cf8e94551
--- /dev/null
+++ b/apps/files/lib/backgroundjob/cleanupfilelocks.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, 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 OCA\Files\BackgroundJob;
+
+use OC\BackgroundJob\TimedJob;
+use OC\Lock\DBLockingProvider;
+
+/**
+ * Clean up all file locks that are expired for the DB file locking provider
+ */
+class CleanupFileLocks extends TimedJob {
+
+ /**
+ * Default interval in minutes
+ *
+ * @var int $defaultIntervalMin
+ **/
+ protected $defaultIntervalMin = 5;
+
+ /**
+ * sets the correct interval for this timed job
+ */
+ public function __construct() {
+ $this->interval = $this->defaultIntervalMin * 60;
+ }
+
+ /**
+ * Makes the background job do its work
+ *
+ * @param array $argument unused argument
+ */
+ public function run($argument) {
+ $lockingProvider = \OC::$server->getLockingProvider();
+ if($lockingProvider instanceof DBLockingProvider) {
+ $lockingProvider->cleanExpiredLocks();
+ }
+ }
+}
diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php
index 4a759d803cd..fb4c60a7640 100644
--- a/lib/private/lock/dblockingprovider.php
+++ b/lib/private/lock/dblockingprovider.php
@@ -233,10 +233,17 @@ class DBLockingProvider extends AbstractLockingProvider {
*/
public function cleanExpiredLocks() {
$expire = $this->timeFactory->getTime();
- $this->connection->executeUpdate(
- 'DELETE FROM `*PREFIX*file_locks` WHERE `ttl` < ?',
- [$expire]
- );
+ try {
+ $this->connection->executeUpdate(
+ 'DELETE FROM `*PREFIX*file_locks` WHERE `ttl` < ?',
+ [$expire]
+ );
+ } catch (\Exception $e) {
+ // If the table is missing, the clean up was successful
+ if ($this->connection->tableExists('file_locks')) {
+ throw $e;
+ }
+ }
}
/**
@@ -255,15 +262,4 @@ class DBLockingProvider extends AbstractLockingProvider {
}
}
}
-
- public function __destruct() {
- try {
- $this->cleanExpiredLocks();
- } catch (\Exception $e) {
- // If the table is missing, the clean up was successful
- if ($this->connection->tableExists('file_locks')) {
- throw $e;
- }
- }
- }
}