Skip to content

Commit

Permalink
more efficient unique share target generation
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Aug 16, 2018
1 parent f7ae235 commit f1b6a69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/MountProvider.php
Expand Up @@ -86,7 +86,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
$mounts = [];
foreach ($superShares as $share) {
try {
$mounts[] = new SharedMount(
$mount = new SharedMount(
'\OCA\Files_Sharing\SharedStorage',
$mounts,
[
Expand All @@ -98,14 +98,15 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
],
$storageFactory
);
$mounts[$mount->getMountPoint()] = $mount;
} catch (\Exception $e) {
$this->logger->logException($e);
$this->logger->error('Error while trying to create shared mount');
}
}

// array_filter removes the null values from the array
return array_filter($mounts);
return array_values(array_filter($mounts));
}

/**
Expand Down
12 changes: 1 addition & 11 deletions apps/files_sharing/lib/SharedMount.php
Expand Up @@ -135,18 +135,8 @@ private function generateUniqueTarget($path, $view, array $mountpoints) {
$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)) {
while ($view->file_exists($path) || isset($mountpoints[$path])) {
$path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
$i++;
}
Expand Down

0 comments on commit f1b6a69

Please sign in to comment.