summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-07-30 17:09:10 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-07-30 17:09:10 +0200
commit30a2e8f9b863ae5434a085ac00947c42ac849036 (patch)
tree4a372de91cda2e7f8cebf228d57ccc08c12a9904 /apps/files_versions
parent6680dd4182962a3d684b8fb1c4bde1a8e5ee5c81 (diff)
downloadnextcloud-server-30a2e8f9b863ae5434a085ac00947c42ac849036.tar.gz
nextcloud-server-30a2e8f9b863ae5434a085ac00947c42ac849036.zip
fix(files_versions): Catch constraint error on version insertion
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/Versions/LegacyVersionsBackend.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
index 1483d03bcc6..9282921e401 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -228,7 +228,27 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setMetadata([]);
- $this->versionsMapper->insert($versionEntity);
+
+ $tries = 1;
+ while ($tries < 5) {
+ try {
+ $this->versionsMapper->insert($versionEntity);
+ /* No errors, get out of the method */
+ return;
+ } catch (\OCP\DB\Exception $e) {
+ if (!in_array($e->getReason(), [
+ \OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION,
+ \OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION,
+ ])
+ ) {
+ throw $e;
+ }
+ /* Conflict with another version, increase mtime and try again */
+ $versionEntity->setTimestamp($versionEntity->getTimestamp() + 1);
+ $tries++;
+ $this->logger->warning('Constraint violation while inserting version, retrying with increased timestamp', ['exception' => $e]);
+ }
+ }
}
public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void {