Skip to content

Commit

Permalink
Merge pull request #1738 from nextcloud/backport/1737/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(DAV): fix getNodeForPath cache
  • Loading branch information
nickvergessen committed Feb 22, 2024
2 parents 03a2947 + 27fd8e4 commit 9aabf1a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
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

0 comments on commit 9aabf1a

Please sign in to comment.