diff options
author | Robin Appelman <robin@icewind.nl> | 2018-08-16 19:16:24 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-08-27 16:25:39 +0200 |
commit | f2152ecda9536659b0149fab4811f366b4cd7c37 (patch) | |
tree | bfd3289f11ac5c836a622dab246a7834b0a0a8c5 /apps/files_sharing | |
parent | f199e7ed17683b19362520cf116701852c456c36 (diff) | |
download | nextcloud-server-f2152ecda9536659b0149fab4811f366b4cd7c37.tar.gz nextcloud-server-f2152ecda9536659b0149fab4811f366b4cd7c37.zip |
more efficient unique share target generation
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedMount.php | 18 |
2 files changed, 10 insertions, 13 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index fd4c537210f..e279b4303a8 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -85,7 +85,7 @@ class MountProvider implements IMountProvider { $mounts = []; foreach ($superShares as $share) { try { - $mounts[] = new SharedMount( + $mount = new SharedMount( '\OCA\Files_Sharing\SharedStorage', $mounts, [ @@ -97,6 +97,7 @@ class MountProvider implements IMountProvider { ], $storageFactory ); + $mounts[$mount->getMountPoint()] = $mount; } catch (\Exception $e) { $this->logger->logException($e); $this->logger->error('Error while trying to create shared mount'); @@ -104,7 +105,7 @@ class MountProvider implements IMountProvider { } // array_filter removes the null values from the array - return array_filter($mounts); + return array_values(array_filter($mounts)); } /** diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 4f0dc89e997..ba3efaf3f87 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -135,20 +135,16 @@ class SharedMount extends MountPoint implements MoveableMount { $name = $pathinfo['filename']; $dir = $pathinfo['dirname']; - // Helper function to find existing mount points - $mountpointExists = function ($path) use ($mountpoints) { - foreach ($mountpoints as $mountpoint) { - if ($mountpoint->getShare()->getTarget() === $path) { - return true; - } - } - return false; - }; - $i = 2; - while ($view->file_exists($path) || $mountpointExists($path)) { + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; + while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; + var_dump($absolutePath); $i++; + if ($i > 10) { + return $path; + } } return $path; |