summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-08-03 15:46:19 +0200
committerRobin Appelman <icewind@owncloud.com>2015-08-03 15:46:19 +0200
commit132a564a217d38a9ac66e26a00d0c1181bd1257a (patch)
tree747b585c50ab0c2effb096491749bf0cb6dffee1
parentc39ded21d2a2388d82e31448639517af0e2a2637 (diff)
downloadnextcloud-server-132a564a217d38a9ac66e26a00d0c1181bd1257a.tar.gz
nextcloud-server-132a564a217d38a9ac66e26a00d0c1181bd1257a.zip
rename path field to key
-rw-r--r--db_structure.xml9
-rw-r--r--lib/private/lock/dblockingprovider.php21
2 files changed, 18 insertions, 12 deletions
diff --git a/db_structure.xml b/db_structure.xml
index 5c2b26e5f15..5633d1537c0 100644
--- a/db_structure.xml
+++ b/db_structure.xml
@@ -1183,7 +1183,7 @@
<table>
<!--
- Table for storing high-level locking
+ Table for storing transactional file locking
-->
<name>*dbprefix*file_locks</name>
@@ -1208,7 +1208,7 @@
</field>
<field>
- <name>path</name>
+ <name>key</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
@@ -1217,6 +1217,7 @@
<field>
<name>ttl</name>
<type>integer</type>
+ <default>-1</default>
<notnull>true</notnull>
<length>4</length>
</field>
@@ -1233,9 +1234,9 @@
<index>
<unique>true</unique>
- <name>lock_path_index</name>
+ <name>lock_key_index</name>
<field>
- <name>path</name>
+ <name>key</name>
<sorting>ascending</sorting>
</field>
</index>
diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php
index d7cbf5d9943..60d516e17c0 100644
--- a/lib/private/lock/dblockingprovider.php
+++ b/lib/private/lock/dblockingprovider.php
@@ -24,6 +24,9 @@ namespace OC\Lock;
use OCP\IDBConnection;
use OCP\Lock\LockedException;
+/**
+ * Locking provider that stores the locks in the database
+ */
class DBLockingProvider extends AbstractLockingProvider {
/**
* @var \OCP\IDBConnection
@@ -38,7 +41,7 @@ class DBLockingProvider extends AbstractLockingProvider {
}
protected function initLockField($path) {
- $this->connection->insertIfNotExist('*PREFIX*file_locks', ['path' => $path, 'lock' => 0, 'ttl' => 0], ['path']);
+ $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => 0, 'ttl' => 0], ['key']);
}
/**
@@ -47,7 +50,7 @@ class DBLockingProvider extends AbstractLockingProvider {
* @return bool
*/
public function isLocked($path, $type) {
- $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `path` = ?');
+ $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `key` = ?');
$query->execute([$path]);
$lockValue = (int)$query->fetchColumn();
if ($type === self::LOCK_SHARED) {
@@ -65,18 +68,20 @@ class DBLockingProvider extends AbstractLockingProvider {
* @throws \OCP\Lock\LockedException
*/
public function acquireLock($path, $type) {
+ $this->connection->beginTransaction();
$this->initLockField($path);
if ($type === self::LOCK_SHARED) {
$result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1 WHERE `path` = ? AND `lock` >= 0',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1 WHERE `key` = ? AND `lock` >= 0',
[$path]
);
} else {
$result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 0',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `key` = ? AND `lock` = 0',
[$path]
);
}
+ $this->connection->commit();
if ($result !== 1) {
throw new LockedException($path);
}
@@ -91,12 +96,12 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->initLockField($path);
if ($type === self::LOCK_SHARED) {
$this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `path` = ? AND `lock` > 0',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `key` = ? AND `lock` > 0',
[$path]
);
} else {
$this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `path` = ? AND `lock` = -1',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = -1',
[$path]
);
}
@@ -114,12 +119,12 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->initLockField($path);
if ($targetType === self::LOCK_SHARED) {
$result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = 1 WHERE `path` = ? AND `lock` = -1',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = 1 WHERE `key` = ? AND `lock` = -1',
[$path]
);
} else {
$result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 1',
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `key` = ? AND `lock` = 1',
[$path]
);
}