diff options
author | Robin Appelman <robin@icewind.nl> | 2018-08-16 19:16:24 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-08-16 19:54:42 +0200 |
commit | 3155c1bd9a40cf0b77e392cf7bc9fad353c820ce (patch) | |
tree | 646f0832de5ca0ff3d1e4b4e1ee15f8c0085e07c /apps/files_sharing/lib | |
parent | f7ae235372ee5647003c407dff7eca83cb7a1322 (diff) | |
download | nextcloud-server-3155c1bd9a40cf0b77e392cf7bc9fad353c820ce.tar.gz nextcloud-server-3155c1bd9a40cf0b77e392cf7bc9fad353c820ce.zip |
more efficient unique share target generation
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_sharing/lib')
-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 cb02a2b5f23..f2fc45dae4e 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -86,7 +86,7 @@ class MountProvider implements IMountProvider { $mounts = []; foreach ($superShares as $share) { try { - $mounts[] = new SharedMount( + $mount = new SharedMount( '\OCA\Files_Sharing\SharedStorage', $mounts, [ @@ -98,6 +98,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'); @@ -105,7 +106,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 1f5b7eaa13e..3dab99115ba 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; |