diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-12 17:13:10 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-11-13 16:05:16 +0300 |
commit | 243516d785a6d1c22600cd4cdd4c5cf9cd21b0d2 (patch) | |
tree | 4388be90cd4e5f00e7f950539f221a95bd9be132 /lib | |
parent | 0737a6fbe4548e512f9fe182c10d5a97390bd16a (diff) |
Fix UniqueConstraintViolationException while insert into oc_file_locks
* fixes #9305 by not being prone to the race condition in insertIfNotExists
* fixes #6899 by not using a query that can result in a deadlock
* replaces the insertIfNotExists call with an insert which is wrapped into a try-catch block
* followup to #12371
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Lock/DBLockingProvider.php | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php index 9de1098a466..f5d92675076 100644 --- a/lib/private/Lock/DBLockingProvider.php +++ b/lib/private/Lock/DBLockingProvider.php @@ -26,6 +26,7 @@ namespace OC\Lock; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OC\DB\QueryBuilder\Literal; use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -116,7 +117,17 @@ class DBLockingProvider extends AbstractLockingProvider { protected function initLockField($path, $lock = 0) { $expire = $this->getExpireTime(); - return $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire], ['key']); + + try { + $builder = $this->connection->getQueryBuilder(); + return $builder->insert('file_locks') + ->setValue('key', $builder->createNamedParameter($path)) + ->setValue('lock', $builder->createNamedParameter($lock)) + ->setValue('ttl', $builder->createNamedParameter($expire)) + ->execute(); + } catch(UniqueConstraintViolationException $e) { + return 0; + } } /** |