Skip to content

Commit 5ba91c4

Browse files
committed
more efficient unique share target generation
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f7ae235 commit 5ba91c4

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

apps/files_sharing/lib/MountProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
8686
$mounts = [];
8787
foreach ($superShares as $share) {
8888
try {
89-
$mounts[] = new SharedMount(
89+
$mount = new SharedMount(
9090
'\OCA\Files_Sharing\SharedStorage',
9191
$mounts,
9292
[
@@ -98,6 +98,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
9898
],
9999
$storageFactory
100100
);
101+
$mounts[$mount->getMountPoint()] = $mount;
101102
} catch (\Exception $e) {
102103
$this->logger->logException($e);
103104
$this->logger->error('Error while trying to create shared mount');

apps/files_sharing/lib/SharedMount.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,8 @@ private function generateUniqueTarget($path, $view, array $mountpoints) {
135135
$name = $pathinfo['filename'];
136136
$dir = $pathinfo['dirname'];
137137

138-
// Helper function to find existing mount points
139-
$mountpointExists = function ($path) use ($mountpoints) {
140-
foreach ($mountpoints as $mountpoint) {
141-
if ($mountpoint->getShare()->getTarget() === $path) {
142-
return true;
143-
}
144-
}
145-
return false;
146-
};
147-
148138
$i = 2;
149-
while ($view->file_exists($path) || $mountpointExists($path)) {
139+
while ($view->file_exists($path) || isset($mountpoints[$path])) {
150140
$path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
151141
$i++;
152142
}

0 commit comments

Comments
 (0)