]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add transaction around mass mounts operations 32038/head
authorJoas Schilling <coding@schilljs.com>
Thu, 21 Apr 2022 09:30:49 +0000 (11:30 +0200)
committerJoas Schilling (Rebase PR Action) <nickvergessen@users.noreply.github.com>
Tue, 7 Mar 2023 19:58:55 +0000 (19:58 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Files/Config/UserMountCache.php

index fe677c5ea52fda1b0ba20fdcb52a65201a9c5d85..a60b39823c5786cbbee432b8b8a50871064810e3 100644 (file)
@@ -130,18 +130,25 @@ class UserMountCache implements IUserMountCache {
 
                $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
 
-               foreach ($addedMounts as $mount) {
-                       $this->addToCache($mount);
-                       /** @psalm-suppress InvalidArgument */
-                       $this->mountsForUsers[$user->getUID()][] = $mount;
-               }
-               foreach ($removedMounts as $mount) {
-                       $this->removeFromCache($mount);
-                       $index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
-                       unset($this->mountsForUsers[$user->getUID()][$index]);
-               }
-               foreach ($changedMounts as $mount) {
-                       $this->updateCachedMount($mount);
+               $this->connection->beginTransaction();
+               try {
+                       foreach ($addedMounts as $mount) {
+                               $this->addToCache($mount);
+                               /** @psalm-suppress InvalidArgument */
+                               $this->mountsForUsers[$user->getUID()][] = $mount;
+                       }
+                       foreach ($removedMounts as $mount) {
+                               $this->removeFromCache($mount);
+                               $index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
+                               unset($this->mountsForUsers[$user->getUID()][$index]);
+                       }
+                       foreach ($changedMounts as $mount) {
+                               $this->updateCachedMount($mount);
+                       }
+                       $this->connection->commit();
+               } catch (\Throwable $e) {
+                       $this->connection->rollBack();
+                       throw $e;
                }
                $this->eventLogger->end('fs:setup:user:register');
        }