Skip to content

Commit 7bbd260

Browse files
committed
fix(Propagator): rollback transaction if it fails
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 462ea0e commit 7bbd260

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

lib/private/Files/Cache/Propagator.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,40 +184,45 @@ public function commitBatch() {
184184
}
185185
$this->inBatch = false;
186186

187-
$this->connection->beginTransaction();
187+
try {
188+
$this->connection->beginTransaction();
188189

189190
$query = $this->connection->getQueryBuilder();
190191
$storageId = (int)$this->storage->getStorageCache()->getNumericId();
191192

192-
$query->update('filecache')
193-
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
194-
->set('etag', $query->expr()->literal(uniqid()))
195-
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
196-
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
193+
$query->update('filecache')
194+
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
195+
->set('etag', $query->expr()->literal(uniqid()))
196+
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
197+
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
197198

198-
$sizeQuery = $this->connection->getQueryBuilder();
199-
$sizeQuery->update('filecache')
200-
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
201-
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
202-
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
203-
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
199+
$sizeQuery = $this->connection->getQueryBuilder();
200+
$sizeQuery->update('filecache')
201+
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
202+
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
203+
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
204+
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
204205

205-
foreach ($this->batch as $item) {
206-
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
207-
$query->setParameter('hash', $item['hash']);
206+
foreach ($this->batch as $item) {
207+
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
208+
$query->setParameter('hash', $item['hash']);
208209

209-
$query->executeStatement();
210+
$query->executeStatement();
210211

211-
if ($item['size']) {
212-
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
213-
$sizeQuery->setParameter('hash', $item['hash']);
212+
if ($item['size']) {
213+
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
214+
$sizeQuery->setParameter('hash', $item['hash']);
214215

215-
$sizeQuery->executeStatement();
216+
$sizeQuery->executeStatement();
217+
}
216218
}
217-
}
218219

219-
$this->batch = [];
220+
$this->batch = [];
220221

221-
$this->connection->commit();
222+
$this->connection->commit();
223+
} catch (\Exception $e) {
224+
$this->connection->rollback();
225+
throw $e;
226+
}
222227
}
223228
}

0 commit comments

Comments
 (0)