From 2aad504e93d1fe89daae150ee062292840bb52cf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Aug 2018 16:10:24 +0200 Subject: [PATCH] use more efficient method to find mountpoint for path Signed-off-by: Robin Appelman --- lib/private/Files/Mount/Manager.php | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 7bd888a6389..eea2b58d5bf 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -70,23 +70,23 @@ class Manager implements IMountManager { */ public function find($path) { \OC_Util::setupFS(); - $path = $this->formatPath($path); - if (isset($this->mounts[$path])) { - return $this->mounts[$path]; - } + $path = Filesystem::normalizePath($path); - \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path)); - $foundMountPoint = ''; - $mountPoints = array_keys($this->mounts); - foreach ($mountPoints as $mountpoint) { - if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) { - $foundMountPoint = $mountpoint; + $current = $path; + while(true) { + $mountPoint = $current . '/'; + if (isset($this->mounts[$mountPoint])) { + return $this->mounts[$mountPoint]; + } + + if ($current === '') { + return null; + } + + $current = dirname($current); + if ($current === '.' || $current === '/') { + $current = ''; } - } - if (isset($this->mounts[$foundMountPoint])) { - return $this->mounts[$foundMountPoint]; - } else { - return null; } }