Skip to content

Commit 2c5bd5a

Browse files
CarlSchwanjoshtrichards
authored andcommitted
fix(Propagator): rollback transaction if it fails
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent dcd4987 commit 2c5bd5a

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

lib/private/Files/Cache/Propagator.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -198,40 +198,45 @@ public function commitBatch() {
198198
}
199199
$this->inBatch = false;
200200

201-
$this->connection->beginTransaction();
201+
try {
202+
$this->connection->beginTransaction();
202203

203-
$query = $this->connection->getQueryBuilder();
204-
$storageId = (int)$this->storage->getStorageCache()->getNumericId();
204+
$query = $this->connection->getQueryBuilder();
205+
$storageId = (int)$this->storage->getStorageCache()->getNumericId();
205206

206-
$query->update('filecache')
207-
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
208-
->set('etag', $query->expr()->literal(uniqid()))
209-
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
210-
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
207+
$query->update('filecache')
208+
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
209+
->set('etag', $query->expr()->literal(uniqid()))
210+
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
211+
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
211212

212-
$sizeQuery = $this->connection->getQueryBuilder();
213-
$sizeQuery->update('filecache')
214-
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
215-
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
216-
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
217-
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
213+
$sizeQuery = $this->connection->getQueryBuilder();
214+
$sizeQuery->update('filecache')
215+
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
216+
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
217+
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
218+
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
218219

219-
foreach ($this->batch as $item) {
220-
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
221-
$query->setParameter('hash', $item['hash']);
220+
foreach ($this->batch as $item) {
221+
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
222+
$query->setParameter('hash', $item['hash']);
222223

223-
$query->executeStatement();
224+
$query->executeStatement();
224225

225-
if ($item['size']) {
226-
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
227-
$sizeQuery->setParameter('hash', $item['hash']);
226+
if ($item['size']) {
227+
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
228+
$sizeQuery->setParameter('hash', $item['hash']);
228229

229-
$sizeQuery->executeStatement();
230+
$sizeQuery->executeStatement();
231+
}
230232
}
231-
}
232233

233-
$this->batch = [];
234+
$this->batch = [];
234235

235-
$this->connection->commit();
236+
$this->connection->commit();
237+
} catch (\Exception $e) {
238+
$this->connection->rollback();
239+
throw $e;
240+
}
236241
}
237242
}

0 commit comments

Comments
 (0)