more efficient unique share target generation
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
969176b116
commit
ee295e2afb
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue