summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Mount/Manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Mount/Manager.php')
-rw-r--r--lib/private/Files/Mount/Manager.php50
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php
index 019dda03a40..1293b8549a5 100644
--- a/lib/private/Files/Mount/Manager.php
+++ b/lib/private/Files/Mount/Manager.php
@@ -38,8 +38,12 @@ class Manager implements IMountManager {
/** @var CappedMemoryCache */
private $pathCache;
+ /** @var CappedMemoryCache */
+ private $inPathCache;
+
public function __construct() {
$this->pathCache = new CappedMemoryCache();
+ $this->inPathCache = new CappedMemoryCache();
}
/**
@@ -48,6 +52,7 @@ class Manager implements IMountManager {
public function addMount(IMountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
$this->pathCache->clear();
+ $this->inPathCache->clear();
}
/**
@@ -60,16 +65,18 @@ class Manager implements IMountManager {
}
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
+ $this->inPathCache->clear();
}
/**
* @param string $mountPoint
* @param string $target
*/
- public function moveMount(string $mountPoint, string $target){
+ public function moveMount(string $mountPoint, string $target) {
$this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
+ $this->inPathCache->clear();
}
/**
@@ -80,32 +87,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 = '';
+ }
+ }
}
/**
@@ -117,6 +121,11 @@ class Manager implements IMountManager {
public function findIn(string $path): array {
\OC_Util::setupFS();
$path = $this->formatPath($path);
+
+ if (isset($this->inPathCache[$path])) {
+ return $this->inPathCache[$path];
+ }
+
$result = [];
$pathLength = \strlen($path);
$mountPoints = array_keys($this->mounts);
@@ -125,12 +134,15 @@ class Manager implements IMountManager {
$result[] = $this->mounts[$mountPoint];
}
}
+
+ $this->inPathCache[$path] = $result;
return $result;
}
public function clear() {
$this->mounts = [];
$this->pathCache->clear();
+ $this->inPathCache->clear();
}
/**