use more efficient method to find mountpoint for path

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-08-16 18:53:32 +02:00
parent 67ae310693
commit bb092553ef
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
1 changed files with 16 additions and 15 deletions

View File

@ -70,23 +70,24 @@ 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])) {
$this->pathCache[$path] = $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;
}
}