summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Mount
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-08-16 18:53:32 +0200
committerRobin Appelman <robin@icewind.nl>2018-08-16 18:55:52 +0200
commitf8116ad4cf5bf806417b3668dea885c672293109 (patch)
treea91b0bc196260b2b9e00a175b18922cf0538eb5b /lib/private/Files/Mount
parent95981810c05100f0439afe6d99973e0f1bd13d39 (diff)
downloadnextcloud-server-f8116ad4cf5bf806417b3668dea885c672293109.tar.gz
nextcloud-server-f8116ad4cf5bf806417b3668dea885c672293109.zip
use more efficient method to find mountpoint for path
this changes the complexity from the number of mounts to the depth of the path Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Mount')
-rw-r--r--lib/private/Files/Mount/Manager.php33
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php
index 019dda03a40..b86142b4d51 100644
--- a/lib/private/Files/Mount/Manager.php
+++ b/lib/private/Files/Mount/Manager.php
@@ -80,32 +80,29 @@ class Manager implements IMountManager {
*/
public function find(string $path) {
\OC_Util::setupFS();
- $path = $this->formatPath($path);
- if (isset($this->mounts[$path])) {
- return $this->mounts[$path];
- }
+ $path = Filesystem::normalizePath($path);
if (isset($this->pathCache[$path])) {
return $this->pathCache[$path];
}
- \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', ['path' => $path]);
- $foundMountPoint = '';
- $mountPoints = array_keys($this->mounts);
- $foundMountPointLength = 0;
- foreach ($mountPoints as $mountpoint) {
- if (\strlen($mountpoint) > $foundMountPointLength && strpos($path, $mountpoint) === 0) {
- $foundMountPoint = $mountpoint;
- $foundMountPointLength = \strlen($foundMountPoint);
+ $current = $path;
+ while(true) {
+ $mountPoint = $current . '/';
+ if (isset($this->mounts[$mountPoint])) {
+ $this->pathCache[$path] = $this->mounts[$mountPoint];
+ return $this->mounts[$mountPoint];
}
- }
- if (isset($this->mounts[$foundMountPoint])) {
- $this->pathCache[$path] = $this->mounts[$foundMountPoint];
- return $this->mounts[$foundMountPoint];
- }
+ if ($current === '') {
+ return null;
+ }
- return null;
+ $current = dirname($current);
+ if ($current === '.' || $current === '/') {
+ $current = '';
+ }
+ }
}
/**