Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(DAV): fix getNodeForPath cache #1738

Merged
merged 1 commit into from Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions .patches/fix-cache-for-node.diff
@@ -0,0 +1,27 @@
diff --git a/lib/DAV/Tree.php b/lib/DAV/Tree.php
index 65b4583ceb..1483e1bc51 100644
--- a/lib/DAV/Tree.php
+++ b/lib/DAV/Tree.php
@@ -62,9 +62,21 @@ public function getNodeForPath($path)
return $this->rootNode;
}

- $parts = explode('/', $path);
$node = $this->rootNode;

+ // look for any cached parent and collect the parts below the parent
+ $parts = [];
+ $remainingPath = $path;
+ do {
+ list($remainingPath, $baseName) = Uri\split($remainingPath);
+ array_unshift($parts, $baseName);
+
+ if (isset($this->cache[$remainingPath])) {
+ $node = $this->cache[$remainingPath];
+ break;
+ }
+ } while ('' !== $remainingPath);
+
while (count($parts)) {
if (!($node instanceof ICollection)) {
throw new Exception\NotFound('Could not find node at path: '.$path);
4 changes: 4 additions & 0 deletions composer.patches.json
@@ -1,4 +1,8 @@
{
"patches": {
"sabre/dav": {
"Fix getNodeForPath cache": ".patches/fix-cache-for-node.diff"
}

}
}
5 changes: 5 additions & 0 deletions composer/installed.json
Expand Up @@ -3912,6 +3912,11 @@
"bin/naturalselection"
],
"type": "library",
"extra": {
"patches_applied": {
"Fix getNodeForPath cache": ".patches/fix-cache-for-node.diff"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions composer/installed.php
Expand Up @@ -3,7 +3,7 @@
'name' => 'nextcloud/3rdparty',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'd7b9f6f5f0513adc3ed652eb84b1822fb5b53032',
'reference' => '330abb953111fee49cd2577b42dcd54712bdb8b0',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down Expand Up @@ -310,7 +310,7 @@
'nextcloud/3rdparty' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'd7b9f6f5f0513adc3ed652eb84b1822fb5b53032',
'reference' => '330abb953111fee49cd2577b42dcd54712bdb8b0',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down
7 changes: 7 additions & 0 deletions sabre/dav/PATCHES.txt
@@ -0,0 +1,7 @@
This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches)
Patches applied to this directory:

Fix getNodeForPath cache
Source: .patches/fix-cache-for-node.diff


14 changes: 13 additions & 1 deletion sabre/dav/lib/DAV/Tree.php
Expand Up @@ -62,9 +62,21 @@ public function getNodeForPath($path)
return $this->rootNode;
}

$parts = explode('/', $path);
$node = $this->rootNode;

// look for any cached parent and collect the parts below the parent
$parts = [];
$remainingPath = $path;
do {
list($remainingPath, $baseName) = Uri\split($remainingPath);
array_unshift($parts, $baseName);

if (isset($this->cache[$remainingPath])) {
$node = $this->cache[$remainingPath];
break;
}
} while ('' !== $remainingPath);

while (count($parts)) {
if (!($node instanceof ICollection)) {
throw new Exception\NotFound('Could not find node at path: '.$path);
Expand Down