aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-08-14 10:32:45 +0200
committerGitHub <noreply@github.com>2024-08-14 10:32:45 +0200
commit1fa9d3987bec22620a534d42d2f1991cbccec351 (patch)
treef1292ec2f208f38fec239f636c160e3fa8c1f527 /apps
parentdbc2e9cdba54720568d5787299aa41e2c565d0b0 (diff)
parent30a2e8f9b863ae5434a085ac00947c42ac849036 (diff)
downloadnextcloud-server-1fa9d3987bec22620a534d42d2f1991cbccec351.tar.gz
nextcloud-server-1fa9d3987bec22620a534d42d2f1991cbccec351.zip
Merge pull request #46887 from nextcloud/fix/versions-catch-insertion-error
Diffstat (limited to 'apps')
-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 b5b948dda5b..90e521abfb4 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -227,7 +227,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 {