Skip to content

Commit e4e8033

Browse files
committed
Add transaction around mass mounts operations
Signed-off-by: Joas Schilling <[email protected]>
1 parent 3dfb5c9 commit e4e8033

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lib/private/Files/Config/UserMountCache.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,25 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC
116116

117117
$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
118118

119-
foreach ($addedMounts as $mount) {
120-
$this->addToCache($mount);
121-
/** @psalm-suppress InvalidArgument */
122-
$this->mountsForUsers[$user->getUID()][] = $mount;
123-
}
124-
foreach ($removedMounts as $mount) {
125-
$this->removeFromCache($mount);
126-
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
127-
unset($this->mountsForUsers[$user->getUID()][$index]);
128-
}
129-
foreach ($changedMounts as $mount) {
130-
$this->updateCachedMount($mount);
119+
$this->connection->beginTransaction();
120+
try {
121+
foreach ($addedMounts as $mount) {
122+
$this->addToCache($mount);
123+
/** @psalm-suppress InvalidArgument */
124+
$this->mountsForUsers[$user->getUID()][] = $mount;
125+
}
126+
foreach ($removedMounts as $mount) {
127+
$this->removeFromCache($mount);
128+
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
129+
unset($this->mountsForUsers[$user->getUID()][$index]);
130+
}
131+
foreach ($changedMounts as $mount) {
132+
$this->updateCachedMount($mount);
133+
}
134+
$this->connection->commit();
135+
} catch (\Throwable $e) {
136+
$this->connection->rollBack();
137+
throw $e;
131138
}
132139
}
133140

0 commit comments

Comments
 (0)