diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml
index a7c3968cb8f2..5227b2f044af 100644
--- a/apps/files/appinfo/info.xml
+++ b/apps/files/appinfo/info.xml
@@ -8,7 +8,7 @@
true
- 1.2.0
+ 1.2.1
diff --git a/apps/files/appinfo/install.php b/apps/files/appinfo/install.php
new file mode 100644
index 000000000000..0815ff2524e9
--- /dev/null
+++ b/apps/files/appinfo/install.php
@@ -0,0 +1,22 @@
+
+ *
+ * @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
+ *
+ */
+
+\OC::$server->getJobList()->add('OCA\Files\BackgroundJob\CleanupFileLocks');
diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php
index 6084435fa5a5..0da6ad04911b 100644
--- a/apps/files/appinfo/update.php
+++ b/apps/files/appinfo/update.php
@@ -104,3 +104,5 @@ function owncloud_reset_encrypted_flag(\OCP\IDBConnection $conn) {
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 000000000000..b5cf8e945513
--- /dev/null
+++ b/apps/files/lib/backgroundjob/cleanupfilelocks.php
@@ -0,0 +1,57 @@
+
+ *
+ * @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
+ *
+ */
+
+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 4a759d803cdd..fb4c60a76408 100644
--- a/lib/private/lock/dblockingprovider.php
+++ b/lib/private/lock/dblockingprovider.php
@@ -233,10 +233,17 @@ public function changeLock($path, $targetType) {
*/
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 @@ public function releaseAll() {
}
}
}
-
- 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;
- }
- }
- }
}