more efficient unique share target generation

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-08-16 19:16:24 +02:00
parent 969176b116
commit ee295e2afb
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 10 additions and 13 deletions

View File

@ -83,7 +83,7 @@ class MountProvider implements IMountProvider {
$mounts = [];
foreach ($superShares as $share) {
try {
$mounts[] = new SharedMount(
$mount = new SharedMount(
'\OCA\Files_Sharing\SharedStorage',
$mounts,
[
@ -95,6 +95,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');
@ -102,7 +103,7 @@ class MountProvider implements IMountProvider {
}
// array_filter removes the null values from the array
return array_filter($mounts);
return array_values(array_filter($mounts));
}
/**

View File

@ -134,20 +134,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;