Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more efficient unique share target generation
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 16, 2018
commit 3155c1bd9a40cf0b77e392cf7bc9fad353c820ce
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
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
18 changes: 7 additions & 11 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,16 @@ 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)) {
$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;
Expand Down