mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
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>
This commit is contained in:
parent
95981810c0
commit
f8116ad4cf
1 changed files with 16 additions and 19 deletions
|
|
@ -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 ($current === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$current = dirname($current);
|
||||
if ($current === '.' || $current === '/') {
|
||||
$current = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->mounts[$foundMountPoint])) {
|
||||
$this->pathCache[$path] = $this->mounts[$foundMountPoint];
|
||||
return $this->mounts[$foundMountPoint];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue