summaryrefslogtreecommitdiffstats
path: root/lib/private/files/cache
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/files/cache')
-rw-r--r--lib/private/files/cache/cache.php14
-rw-r--r--lib/private/files/cache/storage.php15
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 62c32ce6593..64661ca1157 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -214,6 +214,7 @@ class Cache {
* @param array $data
*
* @return int file id
+ * @throws \RuntimeException
*/
public function put($file, array $data) {
if (($id = $this->getId($file)) > -1) {
@@ -251,11 +252,20 @@ class Cache {
return trim($item, "`");
}, $queryParts);
$values = array_combine($queryParts, $params);
- if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values)) {
+ if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [
+ 'storage',
+ 'path_hash',
+ ])) {
return (int)\OC_DB::insertid('*PREFIX*filecache');
}
- return $this->getId($file);
+ // The file was created in the mean time
+ if (($id = $this->getId($file)) > -1) {
+ $this->update($id, $data);
+ return $id;
+ } else {
+ throw new \RuntimeException('File entry exists when inserting and does not exist on select... go away');
+ }
}
}
diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php
index d7d57811a7d..9f2739bbedb 100644
--- a/lib/private/files/cache/storage.php
+++ b/lib/private/files/cache/storage.php
@@ -21,6 +21,7 @@ class Storage {
/**
* @param \OC\Files\Storage\Storage|string $storage
+ * @throws \RuntimeException
*/
public function __construct($storage) {
if ($storage instanceof \OC\Files\Storage\Storage) {
@@ -35,9 +36,17 @@ class Storage {
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
- $sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
- \OC_DB::executeAudited($sql, array($this->storageId));
- $this->numericId = \OC_DB::insertid('*PREFIX*storages');
+ $connection = \OC_DB::getConnection();
+ if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId])) {
+ $this->numericId = \OC_DB::insertid('*PREFIX*storages');
+ } else {
+ $result = \OC_DB::executeAudited($sql, array($this->storageId));
+ if ($row = $result->fetchRow()) {
+ $this->numericId = $row['numeric_id'];
+ } else {
+ throw new \RuntimeException('Storage exists when inserting and does not exist on select... go away');
+ }
+ }
}
}