From 0350d52aabcc40952d32071c79961a0e928437ba Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 22 Jul 2025 14:25:47 +0200 Subject: [PATCH] fix(\OC\DB\Adapter): Ensure insertIfNotExist is atomic Signed-off-by: provokateurin --- lib/private/DB/Adapter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/DB/Adapter.php b/lib/private/DB/Adapter.php index 8f1b8e6d75f48..c02220c244200 100644 --- a/lib/private/DB/Adapter.php +++ b/lib/private/DB/Adapter.php @@ -103,7 +103,10 @@ public function insertIfNotExist($table, $input, ?array $compare = null) { $query .= ' HAVING COUNT(*) = 0'; try { - return $this->conn->executeUpdate($query, $inserts); + $this->conn->beginTransaction(); + $rows = $this->conn->executeUpdate($query, $inserts); + $this->conn->commit(); + return $rows; } catch (UniqueConstraintViolationException $e) { // This exception indicates a concurrent insert happened between // the insert and the sub-select in the insert, which is safe to ignore.