Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
namespace OC\Files\Cache;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\DB\Exceptions\DbalException;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCP\AppFramework\Db\TTransactional;
use OCP\DB\Exception as DBException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryInsertedEvent;
Expand Down Expand Up @@ -72,6 +75,8 @@
* - ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater
*/
class Cache implements ICache {
use TTransactional;

use MoveFromCacheTrait {
MoveFromCacheTrait::moveFromCache as moveFromCacheFallback;
}
Expand Down Expand Up @@ -271,7 +276,8 @@ public function put($file, array $data) {
* @param array $data
*
* @return int file id
* @throws \RuntimeException
* @throws Exception

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OC\Files\Cache\Exception does not exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @throws Exception
* @throws \Exception

* @throws \Throwable
*/
public function insert($file, array $data) {
// normalize file
Expand Down Expand Up @@ -300,6 +306,7 @@ public function insert($file, array $data) {
$storageId = $this->getNumericStorageId();
$values['storage'] = $storageId;

return $this->atomic(function () use ($values, $extensionValues, $file, $storageId, $data) {
try {
$builder = $this->connection->getQueryBuilder();
$builder->insert('filecache');
Expand All @@ -308,7 +315,7 @@ public function insert($file, array $data) {
$builder->setValue($column, $builder->createNamedParameter($value));
}

if ($builder->execute()) {
if ($builder->executeStatement()) {
$fileId = $builder->getLastInsertId();

if (count($extensionValues)) {
Expand All @@ -327,12 +334,9 @@ public function insert($file, array $data) {
$this->eventDispatcher->dispatchTyped($event);
return $fileId;
}
} catch (UniqueConstraintViolationException $e) {
// entry exists already
if ($this->connection->inTransaction()) {
$this->connection->commit();
$this->connection->beginTransaction();
}
} catch (DbalException $e) {
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}

// The file was created in the mean time
Expand All @@ -343,6 +347,8 @@ public function insert($file, array $data) {
throw new \RuntimeException('File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.');
}
}
}, $this->connection);
}

/**
* update the metadata of an existing file or folder in the cache
Expand Down